Codeforces Round #405 (rated, Div. 2, based on VK Cup 2017 Round 1)

A

#include 
#include 
#include 
#include 
#include 
#include 
#include 
#include 
#include 
#include 
#include 
#include 
#include 
#include 

using namespace std;
#define LL long long
#define mst(Arr, x)	memset(Arr, x, sizeof(Arr));
#define pb push_back
#define mk make_pair
#define REP(i, x, n)	for(int i = x; i < n; ++i)
const int qq = 1e5 + 10;
const int INF = 1e9 + 10;
int n;
int gcd(int a, int b){
	return b == 0 ? a : gcd(b, a % b);
}
int lcm(int a, int b){
	return a / gcd(a, b) * b;
}

int main(){
	LL a, b;
	scanf("%lld%lld", &a, &b);
	if(a >= b){
		printf("1\n");
		return 0;
	}
	for(int i = 2; ; ++i){
		a = a * 3LL;
		b = b * 2LL;
		if(a > b){
			printf("%d\n", i);
			return 0;
		}
	}
	return 0;
}

B

對於每一個連通塊,都要求是一個完全字圖

也就是每一個節點的度數都等於這個連通塊頂點的個數 -  1

#include 
#include 
#include 
#include 
#include 
#include 
#include 
#include 
#include 
#include 
#include 
#include 
#include 
#include 

using namespace std;
#define LL long long
#define mst(Arr, x)	memset(Arr, x, sizeof(Arr));
#define pb push_back
#define mk make_pair
#define REP(i, x, n)	for(int i = x; i < n; ++i)
const int qq = 3e5 + 10;
const int INF = 1e9 + 10;
int n, m;
int deg[qq];
int gcd(int a, int b){
	return b == 0 ? a : gcd(b, a % b);
}
int lcm(int a, int b){
	return a / gcd(a, b) * b;
}
int fa[qq];
int Find(int x){
	return fa[x] == -1 ? x : fa[x] = Find(fa[x]);
}
queue Q[qq];
int main(){
	mst(fa, -1);
	mst(deg, 0);
	scanf("%d%d", &n, &m);
	for(int i = 0; i < m; ++i){
		int a, b;
		scanf("%d%d", &a, &b);
		deg[a]++, deg[b]++;
		int x = Find(a), y = Find(b);
		if(x != y)	fa[y] = x;
	}
	for(int i = 1; i <= n; ++i){
		Q[Find(i)].push(i);
	}
	bool flag = true;
	for(int i = 1; i <= n; ++i){
		if(Q[i].size() == 0)	continue;
		int k = Q[i].size() - 1;
		Q[i].pop();
		while(!Q[i].empty()){
			int v = Q[i].front();
			Q[i].pop();
			if(k != deg[v])	flag = false;
		}
	}
	if(flag)	printf("YES\n");
	else	printf("NO\n");
	return 0;
}

C

對於每一個假設第i個區間是NO, 假設這個區間的最右端是r, 讓str[r] = str[r - k + 1] 相等即可, 它不影響其他的連續區間

#include 
#include 
#include 
#include 
#include 
#include 
#include 
#include 
#include 
#include 
#include 
#include 
#include 
#include 

using namespace std;
#define LL long long
#define mst(Arr, x)	memset(Arr, x, sizeof(Arr));
#define pb push_back
#define mk make_pair
#define REP(i, x, n)	for(int i = x; i < n; ++i)
const int qq = 1e5 + 10;
const int INF = 1e9 + 10;
int n, k;
int gcd(int a, int b){
	return b == 0 ? a : gcd(b, a % b);
}
int lcm(int a, int b){
	return a / gcd(a, b) * b;
}
string str[105];
string name[105];
int num[105];
string f;
map mp;
int main(){
	for(int i = 1; i <= 26; ++i)
		name[i] = 'A' + (i - 1);
	for(int i = 27; i <= 26*2; ++i){
		name[i] = name[i - 26] + "c";
	}
	cin >> n >> k;
	int p = 1;
	for(int i = 1; i < k; ++i)
		str[i] = name[p++];
	for(int i = k; i <= n; ++i){
		cin >> f;
		if(f == "YES"){
			str[i] = name[p++];
		}else{
			str[i] = str[i - k + 1];
		}
	}
	for(int i = 1; i <= n; ++i){
		if(str[i] == "")	str[i] = name[p++];
	}
	for(int i = 1; i <= n; ++i)
		cout << str[i] << " ";
	return 0;
}


你可能感兴趣的:(codeforces)