本人刚打cf几天,如果题解不清楚请谅解或在评论区留言,并感谢有div4场次让我能感受到AK的快乐
Problem - A - CodeforcesCodeforces. Programming competitions and contests, programming communityhttps://codeforces.com/contest/1669/problem/AA题就不用多说了吧,就是for+if else
inline void solve() {
int n;
scanf("%d", &n);
if (n <= 1399) {
printf("Division 4\n");
} else if (n > 1399 && n <= 1599) {
printf("Division 3\n");
} else if (n > 1599 && n <= 1899) {
printf("Division 2\n");
} else {
printf("Division 1\n");
}
}
Problem - B - Codeforceshttps://codeforces.com/contest/1669/problem/B这一题就是统计数组中出现的数,只要有一个数出现3次就可以直接输出了,可以用map实现
void solve() {
int n;
scanf("%d", &n);
map<int, int> mp;
int a;
bool flag = true;
for (int i = 1; i <= n; i++) {
scanf("%d", &a);
if (flag)
if (++mp[a] >= 3) {
printf("%d\n", a);
flag = false;
//break;
}
}
if (flag)
printf("-1\n");
}
Problem - C - CodeforcesCodeforces. Programming competitions and contests, programming communityhttps://codeforces.com/contest/1669/problem/C?直接记录数组前两位数,如果奇数位数字与last1奇偶性不同或者偶数位数字与last奇偶性不同那就永远无法得到全偶数或全奇数序列
inline void solve() {
int n;
scanf("%d", &n);
if (n == 2) {
printf("YES\n");
return;
}
int last1;
int last2;
scanf("%d %d", &last1, &last2);
int t;
bool flag = true;
for (int i = 3; i <= n; i++) {
scanf("%d", &t);
if (flag)
if (i & 1) {
if (last1 % 2 != t % 2) {
flag = false;
}
} else {
if (last2 % 2 != t % 2) {
flag = false;
}
}
}
if (flag) {
printf("YES\n");
} else {
printf("NO\n");
}
}
Problem - D - Codeforceshttps://codeforces.com/contest/1669/problem/D可以想到在遇见W之前任意序列长大于等于2的BR序列都可以由彩票油印出来,但只含R或B序列就无法油印出,然后模拟一下这个操作即可。
inline void solve() {
int n;
scanf("%d", &n);
string s;
cin >> s;
if (n == 1 && s[0] != 'W') {
printf("NO\n");
return ;
}
int cnt = 0;
char last;
bool flag = true;
map<char, int> mp;
for (int i = 0; i < s.length(); i++) {
mp[s[i]] = 1;
if (flag)
if (s[i] == 'W') {
if (cnt == 1) {
flag = false;
}
if ((mp['B'] + mp['R']) % 2) {
flag = false;
}
cnt = 0;
mp['B'] = 0;
mp['R'] = 0;
} else {
cnt++;
}
}
if (cnt == 1 || (mp['B'] + mp['R']) % 2) {
flag = false;
}
if (flag) {
printf("YES\n");
} else {
printf("NO\n");
}
}
Problem - F - Codeforceshttps://codeforces.com/contest/1669/problem/F先把A从左边能吃到的糖果用map预处理一下,然后再从右边开始一个一个吃,如果两人吃的糖果数能小于等于n且两人总共吃的一样则更新答案,如果两人总共吃的一样多了但两人加起来的数目超过了n则可以直接退出了,因为在之后不可能成立了。
ll s[MAXN];
inline void solve() {
int n;
scanf("%d", &n);
map<ll, int> mp;
ll sum = 0;
for (int i = 1; i <= n; i++) {
scanf("%lld", s + i);
sum += s[i];
mp[sum] = i;
}
int t;
ll cnt = 0;
bool flag = true;
sum = 0;
for (int i = n; i >= 1; i--) {
sum += s[i];
//printf("%d ", t);
if (mp[sum]) {
if (mp[sum] + n - i + 1 > n) {
break;
}
cnt = mp[sum] + n - i + 1;
}
}
printf("%lld\n", cnt);
}
Problem - E - Codeforceshttps://codeforces.com/contest/1669/problem/E可以通过map来记录第一位字符和第二位字符的数目,同时也记录字符串出现的次数,当记录到第i个字符串时如果前面有与第一位相同或与第二位相同的字符串直接加上,若这个字符串之前出现过则要减去其*2,因为把第一位和第二位都算上了。
inline void solve() {
int n;
scanf("%d", &n);
string s;
map<string, int> mp;
map<char, int> mp1;
map<char, int> mp2;
ll ans = 0;
for (int i = 1; i <= n; i++) {
cin >> s;
ans += mp1[s[0]]++;
ans += mp2[s[1]]++;
ans -= mp[s] * 2;
mp[s]++;
}
printf("%lld\n", ans);
}
Problem - H - CodeforcesCodeforces. Programming competitions and contests, programming communityhttps://codeforces.com/contest/1669/problem/H题意很明确就是从最高位开始找能否让该位变1,先把数组中每个数的每一位出现的次数记录一下,然后再从最高位开始看所剩操作能否支持其变1
ll a[MAXN];
inline void solve() {
int n, k;
int b[50] = {0};
scanf("%d %d", &n, &k);
for (int i = 1; i <= n; i++) {
scanf("%d", a + i);
for (int j = 0; j <= 30; j++) {
if ((a[i] >> j) & 1) {
b[j]++;
}
}
}
int ans = 0;
for (int i = 30; i >= 0; i--) {
if (k >= n - b[i]) {
k -= n - b[i];
ans |= 1 << i;
}
}
printf("%d\n", ans);
}
|