其他分享
首页 > 其他分享> > Codeforces Round #784 (Div. 4)

Codeforces Round #784 (Div. 4)

作者:互联网

A. Division?

代码:

#include <bits/stdc++.h>
using namespace std;
#define int long long
const int N = 2e5 + 10;
int q[N];
 
void solve() {
	int x;
	cin >> x;
	if(x <= 1399) cout << "Division 4" << endl;
	else if(x <= 1599) cout << "Division 3" << endl;
	else if(x <= 1899) cout << "Division 2" << endl;
	else cout << "Division 1" << endl;
}
signed main() {
	int t;
	cin >> t;
	while(t--) {
		solve();
	}
	return 0;
} 

B. Triple

代码:

#include <bits/stdc++.h>
using namespace std;
#define int long long
const int N = 2e5 + 10;
int q[N], cnt[N];
 
void solve() {
	int n;
	cin >> n;
	for(int i = 0; i <= n; i++) cnt[i] = 0;
	//memset(cnt, 0, sizeof cnt);
	for(int i = 0; i < n; i++) {
		cin >> q[i];
		cnt[q[i]] ++;
	}
	int ans = 0, maxv = 0;
	for(int i = 0; i <= n; i++) {
		if(cnt[i] >= 3) {
			maxv = i;
			ans++;
		}
	}
	if(ans == 0) cout << -1 << endl;
	else cout << maxv << endl;
}
signed main() {
	int t;
	cin >> t;
	while(t--) {
		solve();
	}
	return 0;
} 

C - Odd/Even Increments

代码:

#include <bits/stdc++.h>
using namespace std;
#define int long long
const int N = 60;
int q[N], cnt[N];
 
void solve() {
	int n;
	cin >> n;
	for(int i = 1; i <= n; i++) {
		cin >> q[i];
	}
	int t = q[1] % 2, tt = q[2] % 2;
	bool flag = true;
	for(int i = 1; i <= n; i += 2) {
		if(q[i] % 2 != t) {
			flag = false;
			break;
		}
	}
	for(int i = 2; i <= n; i += 2) {
		if(q[i] % 2 != tt) {
			flag = false;
			break;
		}
	}
	if(flag) puts("YES");
	else puts("NO"); 
}
signed main() {
	int t;
	cin >> t;
	while(t--) {
		solve();
	}
	return 0;
} 

D. Colorful Stamp

代码:

#include <bits/stdc++.h>
using namespace std;
#define int long long
//const int N = 2e5 + 10;
//int q[N], cnt[N];
 
void solve() {
	int n;
	string s;
	cin >> n >> s;
		int r = 0, b = 0, cnt = 0;
		for(int i = 0; i < n; i++) {
			if(s[i] == 'W') {
				if((r == 0 || b == 0 ) && cnt) {
					puts("NO");
					return;
				}else {
					r = 0, b = 0, cnt = 0;
				}
			} else {
				if(s[i] == 'R') r++, cnt++;
				else if(s[i] == 'B') b++, cnt++;
			}
		}
		if((r == 0 || b == 0) && cnt) {
			puts("NO");
		}else {
			puts("YES");
		}
 
}
signed main() {
	int t;
	cin >> t;
	while(t--) {
		solve();
	}
	return 0;
} 

E. 2-Letter Strings

代码:

#include <bits/stdc++.h>
using namespace std;
#define int long long
const int N = 1e5 + 10;
//int q[N], cnt[N];
int cnt[11][11];
int l[11], r[11];
void solve() {
	int n;
	cin >> n;
	memset(cnt, 0, sizeof cnt);
	memset(l, 0, sizeof l);
	memset(r, 0, sizeof r);
	for(int i = 0; i < n; i++) {
		char a, b;
		cin >> a >> b;
		cnt[a-'a'][b-'a']++;
		l[a-'a']++;
		r[b-'a']++;
	}
	int ans = 0;
	for(int i = 0; i < 11; i++)
		for(int j = 0; j < 11; j++) {
			if(cnt[i][j]) {
				ans += (l[i] + r[j] - 2 * cnt[i][j]) * cnt[i][j];
			}
		}
	cout << ans / 2 << endl;
}
signed main() {
	int t;
	cin >> t;
	while(t--) {
		solve();
	}
	return 0;
} 

F. Eating Candies

代码:

#include <bits/stdc++.h>
using namespace std;
#define int long long
const int N = 2e5 + 10;
//int q[N], cnt[N];
//int cnt[11][11];
//int l[11], r[11];
int w[N];
void solve() {
	int n;
	cin >> n;
	for(int i = 1; i <= n; i++) cin >> w[i];
	int ans = 0, a = 0, b = 0;
	int i = 0, j = n + 1;
	while(i < j) {
		if(a == b) {
			ans = i + (n - j + 1);
			a += w[++i], b += w[--j];
			//cout << i << ' ' << j << ' ' << ans << endl;
		}
		else if(a > b) b += w[--j];// cout << "b" << b << endl;
		else if(a < b) a += w[++i];// cout << "a" << a << endl; 
	}
	cout << ans << endl;
}
signed main() {
	int t;
	cin >> t;
	while(t--) {
		solve();
	}
	return 0;
} 

G. Fall Down

#include <bits/stdc++.h>
using namespace std;
#define int long long
const int N = 2e5 + 10;
//int q[N], cnt[N];
//int cnt[11][11];
//int l[11], r[11];
char w[50][50];
void solve() {
	int n, m;
	cin >> n >> m;
	for(int i = 0; i < n; i++)
		for(int j = 0; j < m; j++) 
			cin >> w[i][j];
	for(int j = 0; j < m; j++) {
		for(int i = n - 1; i >= 0; i--) {
			if(w[i][j] == '*') {
				while(w[i+1][j] == '.' && (i + 1 < n)) swap(w[i][j], w[i+1][j]), i++;
			}
		}
	}
	for(int i = 0; i < n; i++) {
		for(int j = 0; j < m; j++) {
			cout << w[i][j];
		}
		cout << endl;
	}
}
signed main() {
	int t;
	cin >> t;
	while(t--) {
		solve();
	}
	return 0;
} 

H. Maximal AND

#include <bits/stdc++.h>
using namespace std;
#define int long long
const int N = 2e5 + 10;
//int q[N], cnt[N];
//int cnt[11][11];
//int l[11], r[11];
int cnt[40];
int a[N];
//char w[50][50];
void solve() {
	int n, k;
	cin >> n >> k;
	memset(cnt, 0, sizeof cnt);
	for(int i = 0; i < n; i++) {
		int t;
		cin >> t; 
		int tt = 0;
		while(t) {
			cnt[tt++] += t % 2;
			t /= 2;
		}
	}
	int pos = 31;
			for(int i = 30; i >= 0; i--) {
				if(n - cnt[i] <= k) {
					k -= n-cnt[i];
					cnt[i] = n;
				}
				if(k <= 0) break;
			}
	int ans = 0;
	for(int i = 30; i >= 0; i--) {
		if(cnt[i] == n) ans += pow(2,i);
	}
	cout << ans << endl;
}
signed main() {
	int t;
	cin >> t;
	while(t--) {
		solve();
	}
	return 0;
} 

标签:784,11,cnt,int,Codeforces,long,++,solve,Div
来源: https://www.cnblogs.com/MoonSkyy/p/16178266.html