跳到正文

个人记录

Educational Codeforces Round 135 (Rated for div 2) 比赛记录

hyacinthwxy约 6 分钟
原文
文章信息与版本

文章信息

收录
2025年12月12日
更新
2026年5月21日
篇幅
约 6 分钟

版本

  1. v1当前

比赛链接:https://codeforces.com/contest/1728

比赛成绩

SolvedPenaltyABCDEFG
44176176+1+1+3+3+2+2+3+3
00:0500:0500:2800:2800:5300:5301:3001:30
upsolved

比赛过程

前面思路还算顺利,想题的时候很自信,但是神奇地写出一大堆bug,最后没时间写完E了(大哭

题解

A. Colored Balls: Revisited

思路

容易证明只要某种颜色的数量小于等于球的总数/2,这种颜色必然可以被全部消掉。判一下就可以了。

代码

C++
#include <bits/stdc++.h>
using namespace std;
int t,n,cnt[25],sum,flag;
int main(){
	cin >> t;
	while(t--){
		cin >> n;
		flag = sum = 0;
		for(int i = 1;i <= n;i++){
			cin >> cnt[i];
			sum += cnt[i];
		}
		for(int i = 1;i <= n;i++)
			if(cnt[i] > sum / 2){
				flag = i;
				break;
			}
		if(!flag) cout << n << '\n';
		else cout << flag << '\n';
	}
	return 0;
}

B. Best Permutation

思路

先考虑最后一个放什么,想让结果最大,最后一个应该放最大的数,也就是n(因为这样不容易归零,并且在前面的结果上加的多)。既然最后已经放了n,那前面的结果最大只能加到n-1,我们不妨直接在倒数第二位放上n-1,这样只需要把前n-2位构造出答案是0的情况就可以了。

如果n是偶数,可以把前面按照从大到小的顺序构造,每两位就会清零一次,可以保证答案是0。但是n是奇数时还会多出一个1,这时注意到“1 2 3”这个序列的答案是0,也就是说只需要把最后三个数由“3 2 1”改为“1 2 3”就可以满足要求。

代码

C++
#include <bits/stdc++.h>
using namespace std;
int t,n;
int main(){
	cin >> t;
	while(t--){
		cin >> n;
		if(n == 4) cout << "2 1 3 4\n";
		else{
			for(int i = 1;i <= n - 5;i++) cout << n - 2 - i + 1 << ' ';
			if(n % 2) cout << "1 2 3 ";
			else cout << "3 2 1 ";
			cout << n - 1 << ' ' << n << '\n';
		}
	}
	return 0;
}

C. Digital Logarithm

思路

因为数据范围在1e9以内,所以不会出现f是两位数的情况。直接相等的数优先匹配,没有的话位数相同的优先,还没有就全部变成1。

代码

C++
#include <bits/stdc++.h>
using namespace std;
int t,n,a[200005],b[200005],c[200005],d[200005],d2[200005],tmp;
int main(){
	cin >> t;
	while(t--){
		cin >> n;
		for(int i = 1;i <= n;i++) cin >> a[i];
		for(int i = 1;i <= n;i++) cin >> b[i];
		tmp = 0,b[0] = 0;
		for(int i = 1;i <= n;i++){
			while(b[tmp] < a[i]) tmp++;
			d[i] = b[tmp] - a[i];
		}
		c[n + 1] = n,b[0] = 0x3f3f3f3f;
		for(int i = n;i > 0;i--){
			if(a[i] <= b[i - 1]) c[i] = c[i + 1];
			else c[i] = i - 1;
			d2[i] = b[c[i + 1]] - a[i];
		}
		for(int i = 1;i <= n;i++) cout << d[i] << ' ';
		cout << '\n';
		for(int i = 1;i <= n;i++) cout << d2[i] << ' ';
		cout << '\n';
	}
	return 0;
}

D. Letter Picking

思路

因为每次选字母都是放进各自字符串的开头,所以可以倒着想。发现最后剩两个字符时,Alice一定选更小的那个,所以除非两个字符相同,否则Alice必赢。再往回推,剩四个字符时,除非Bob可以选到与Alice相同的字符串,Alice也是必赢。以此类推,Bob不可能赢。

因此,Bob会尽量使结果变成“Draw”。分析一下,如果在某一步Bob可以拿到跟Alice一样的字符,一定是不管Alice怎么拿都可以做到的,不外乎两种可能:目前字符串的两端都和它们各自相邻的字符相等,或是这两端相等。进一步发现,如果可以使结果变成平局,整个字符串一定是后者中包含了一些前者(两者都可以为空)。检查是否满足这个条件即可。

C++
#include <bits/stdc++.h>
using namespace std;
int t,tmp,flag;
string s;
char c[2005];
int main(){
	cin >> t;
	while(t--){
		cin >> s;
		flag = 0,tmp = s.length();
		for(int i = 0;i < s.length() / 2;i++)
			if(s[i] != s[s.length() - i - 1]){
				tmp = i;
				break;
			}
		for(int i = tmp;i < s.length() - tmp;i++)
			if((i - tmp) % 2 && s[i] != s[i - 1]){
				flag = 1;
				break;
			}
		if(flag) cout << "Alice\n";
		else cout << "Draw\n";
	}
	return 0;
}

E. Red-Black Pepper

思路

代码

C++

F. Fishermen

思路

代码

C++

G. Illumination

思路

代码

C++

~~~~~~~qwqqwqqwqqwqqwq~~~~~~~

原文