Codeforces Round #696 (Div. 2)

这次比赛很玄学,也可能是自己太困了吧,直接爆 0
但是第二天醒来重新做,做出来两道。。。

A. Puzzle From the Future
题目链接:https://codeforces.com/problemset/problem/1474/A
思路:
a的第一个字符一定是 1 , 将 aa = a[i - 1] + b[i - 1] ,则 aa 有三种取值:0 , 1 , 2 ; a[i] 、b[i] 有两种取值:0 , 1 ,枚举这几种情况就可。

#include<iostream>
#include<cstring>
#include<cstdio>
#include<string.h> 
using namespace std;
char a[100010];
int main(){
	string b; 
	int t , n ;
	cin >> t;
	while(t --){
		scanf("%d",&n);
		cin >> b;
		a[0] = '1' ;
		for(int i = 1 ; i < n ; i ++){
			char aa = (a[i - 1] - '0') + (b[i - 1] - '0') + '0';
			if(b[i] == '1' && (aa == '0' || aa == '1')) a[i] = '1' ;
			else if(b[i] == '1' && aa == '2') a[i] = '0';
			
			if(b[i] == '0' && (aa == '0' || aa == '2')) a[i] = '1' ;
			else if(b[i] == '0' && aa == '1') a[i] = '0' ;
		}
			
		for(int i = 0 ; i < n ; i ++) printf("%c",a[i]);
		puts("");
	}
	
	return 0; 
}

B. Different Divisors
题目链接:https://codeforces.com/problemset/problem/1474/B
思路:
1.题目要求找至少有 4 个因子并且各因子的差至少为 d ,且这个数是最小的。
2.不过根据贪心可得正好 4 个因子是 4 个以上因子里面最小的 ;
3.所以我们要找的不是至少有 4 个因子的整数,而是恰好有 4 个因子的整数 ,且有两个已经确定,即:1 和 该数本身 。
4.那么在满足只有 4 个因子的情况下,另外两个因子只能是质数才能保证该数恰好有 4 个因子 。
5.第一个因子最小是 d + 1 (d + 1 - 1 >= d), 第二个因子最小是 2 * d + 1 (2 * d + 1 - d - 1 >= d)
6.第一个因子从 d + 1 开始枚举 , 如果不是质数,就把两个因子都 + 1 (保证两个因子的差 >= d),直到遇到一个质数为止;
7.第二个因子从 2 * d + 1 加上因为第一个因子枚举时加的数 开始枚举 , 如果不是质数,就只把第二个因子 + 1 ,直到遇到一个质数为止。
8.最后将两个因子相乘 就是 结果。

#include<iostream>
#include<cstring>
#include<cstdio>
using namespace std;

int judge(int x){
	for(int i = 2 ; i <= x / i ; i ++){
		if(x % i == 0) return 0;
	}
	return 1 ;
}

int main(){
	int t , d;
	cin >> t;
	while(t --){
		scanf("%d",&d);
		int a = d + 1 ;
		int b = 2 * d + 1;
		while(judge(a) == 0){
			a ++ , b ++;
		} 
		while(judge(b) == 0){
			b ++;
		}
		int res = a * b;
		printf("%d
",res);
	}
	return 0;
}

这次比赛让我知道了困的时候不要勉强,否则会WA的很惨。
还是头脑清醒的时候做题比较好哇。

原文地址:https://www.cnblogs.com/ZhaoHaoFei/p/14301989.html