20201122模拟

感觉今天的模拟还比较简单????但是考场上还是懒得动脑子吧,而且裹着大衣,头脑也比较糊涂

T1和T3考场都和正解差一点,T3想二分但是\(check\)函数并不是很有把握,而且正确性也是很迷惑

期望:60+20+?+10,实际20+20+40+40,改后100+20+100+40

T1

solution

构造题,根据一系列的举例子,可以发现只有\(b\leq a-2\)的时候才有解,且\(b=a-3\)的时候无解

先考虑\(b =a-2\)的情况,形状类似一个二叉树,并且根多连了一个点

再考虑\(b\leq a-4\)的情况,和上一种情况差不多,相当于一个二叉树,但是度为1的点比较多,所以余出一个点,在他上面连边凑数

注意!!特判\(a=b=1\)的情况,输出1,就离谱

code
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <cstring>
using namespace std;
int read(){
	int x = 1,a = 0;char ch = getchar();
	while (ch < '0'||ch > '9'){if (ch == '-') x = -1;ch = getchar();}
	while (ch >= '0'&&ch <= '9'){a = a*10+ch-'0';ch = getchar();}
	return x*a;
}
int a,b;
int main(){
	a = read(),b = read();
	if (b == a-2){
		if (b){
			printf("%d\n",a+b);
			printf("%d %d\n",1,2);
			printf("%d %d\n",1,3);
			printf("%d %d\n",1,4);
			int root = 4;
			for (int i = 5;i <= a+b;i++){
				printf("%d %d\n",root,i);
				if (i-root == 2) root = i;
			}
		}
		else printf("2\n1 2\n");
	}
	else if (b <= a-4){
		printf("%d\n",a+b+1);
		printf("1 2\n");
		int root = 2;
		for (int i = 3;i <= 2*b+2;){
			for (int j = 1;j <= 2;j++,i++) printf("%d %d\n",root,i);
			root += 2;
		} 
		for (int i = 2*b+3;i <= a+b+1;i++){
			printf("%d %d\n",1,i);
		}
	}
	else{
		if(a==0&&b==0) puts("1");
		else puts("0");
	}
	return 0;
}

T2

solution

\(n=0\)直接输出答案

code
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <cstring>
#include <queue>
using namespace std;
int read(){
	int x = 1,a = 0;char ch = getchar();
	while (ch < '0'||ch > '9'){if (ch == '-') x = -1;ch = getchar();}
	while (ch >= '0'&&ch <= '9'){a = a*10+ch-'0';ch = getchar();}
	return x*a;
}
int t;
double ans;
int main(){
	freopen("roll.in","r",stdin);
	freopen("roll.out","w",stdout);
	t = read();
	while (t--){
		int n = read(),u = read(),k = read();
		if (n == 0) ans = u*k*1.0;
		printf("%.10lf\n",ans);
	}
	return 0;
}

T3

solution

上来看题就想到了二分,直接上,哎?直接\(O(m)\)dfs不香么,开始直接dfs……

哎??怎么有点不对的样子,怎么又有点对的样子,算了,就这样把,回过头再看,好像还是二分把,开始混乱,直接交吧,不改了

思路还是挺明显的,二分最终的疲惫值,看是否能得到一个合法路径

单调性显然能满足大的就一定能满足更大的,不满足小的肯定满足不了更小的。不过我写的玄学代码还过了40

code
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <cstring>
#include <queue>
#define int long long
using namespace std;
int read(){
	int x = 1,a = 0;char ch = getchar();
	while (ch < '0'||ch > '9'){if (ch == '-') x = -1;ch = getchar();}
	while (ch >= '0'&&ch <= '9'){a = a*10+ch-'0';ch = getchar();}
	return x*a;
}
const int maxn = 1e6+10;
int n,m;
struct node{
	int to,nxt,w;
}ed[maxn];
int head[maxn],tot;
void add(int u,int to,int w){
	ed[++tot].to = to;
	ed[tot].w = w;
	ed[tot].nxt = head[u];
	head[u] = tot;
}
bool vis[maxn];
int dis[maxn];
bool check(int s){
	queue<int> q;q.push(1);
	memset(vis,0,sizeof(vis));vis[1] = 1;memset(dis,0,sizeof(dis));
	while (!q.empty()){
		int x = q.front();q.pop();
		for (int i = head[x];i;i = ed[i].nxt){
			int to = ed[i].to;
			if(vis[to]) continue;
			dis[to] = dis[x]+1;
			if (dis[to]*ed[i].w > s) continue;
			vis[to] = 1;
			q.push(to);
		}
	}
	return vis[n];
}
signed main(){
	n = read(),m = read();
	for (int i = 1;i <= m;i++){
		int a = read(),b = read(),c = read();
		add(a,b,c);
	}
	int l = 0,r = 3e14+10;
	while (l < r){
		int mid = (l+r)>>1;
		if (check(mid)) r = mid;
		else l = mid+1;
	}
	printf("%lld\n",r);
	return 0;
}

T4

solution

并不知道自己写的什么奇奇怪怪的东西,复杂度好像是\(O(n^2)\)的,但是过了1e7就离谱

code
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <cstring>
#include <queue>
#define int long long
using namespace std;
int read(){
	int x = 1,a = 0;char ch = getchar();
	while (ch < '0'||ch > '9'){if (ch == '-') x = -1;ch = getchar();}
	while (ch >= '0'&&ch <= '9'){a = a*10+ch-'0';ch = getchar();}
	return x*a;
}
int l,r,ans;
signed main(){
	freopen("triad.in","r",stdin);
	freopen("triad.out","w",stdout);
	l = read(),r = read();
	for (int i = l;i <= r;i++){
		int res = r/i;
		for (int j = 2;j <= res;j++){
			ans += res/j-1;
		}
	}
	printf("%lld\n",ans);
}
posted @ 2020-11-22 15:11  小又又yyyy  阅读(97)  评论(0编辑  收藏  举报