Educational Codeforces Round 121 (Rated for Div. 2) (A ~ C)

Posted Ja_King_ZH

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了Educational Codeforces Round 121 (Rated for Div. 2) (A ~ C)相关的知识,希望对你有一定的参考价值。

A.https://codeforces.com/contest/1626/problem/A

题意:给你个字符串,使得每个字母出现次数不超过两次,输出字符串,使得输出的字符串相同字母距离相同。
题解:sort一下即可

int main()

	int t;
	cin >> t;
	while (t--)
	
		string s;
		cin >> s;
		sort(s.begin(), s.end());
		cout << s << endl;
	
	return 0;

B.https://codeforces.com/contest/1626/problem/B

题意:给定一个数字字符串,合并相邻两个数字,并替换原数字,使得结果最大。
题解:首先从尾到头(因为999转化为918大于189,所以从尾到头)查找有无相加为两位数的,若有,则替换,否则,将开头两字母相加替换。

const int N = 1e5 + 10;

int main()

	int t;
	cin >> t;
	while (t--)
	
		string s;
		cin >> s;
		int f = 1;
		for (int i = s.size() - 2; i >= 0; i--)
		
			int x = s[i] + s[i + 1] - '0' - '0';
			if (x >= 10)
			
				s[i] = '1';
				s[i + 1] = x - 10 + '0';
				f = 0;
				break;
			
		
		if (f)
		
			cout << s[0] + s[1] - '0' - '0';
			
			for (int i = 2; i < s.size(); i++)
				cout << s[i];
			cout << endl;
		
		else cout << s << endl;
	
	return 0;

C.https://codeforces.com/contest/1626/problem/C

题意:闯关,给定第i个关卡怪物出现的时间,以及打败怪物的所需魔法值,怪物出现时间一定大于打败怪物所需魔法值。你在第i秒拥有x魔法值,你可以在下一秒使得魔法值变为x+1,或者1,问打败怪物所需最小魔法值。
题解:贪心,设当前打败怪物魔法值为x,若下一个怪物出现的时间差小于打败怪物的魔法,则x+1,否则变为1。(但需预处理怪物魔法值!!!!因为这个wa了四次!!!!)

typedef long long ll;
const int N = 110;
ll a[N], b[N];

int main()

	int t;
	cin >> t;
	while (t--)
	
		int n;
		cin >> n;
		for (int i = 1; i <= n; i++)
		
			cin >> a[i];
		
		for (int i = 1; i <= n; i++)
		
			cin >> b[i];
		
		for (int i = n - 1; i; i--) 
			b[i] = max(b[i], b[i + 1] - (a[i + 1] - a[i]));
		
		ll ans = 0, last = -1;
		for (int i = 1; i <= n; i++)
		
			if (i - 1)
			
				ll x = a[i], y = b[i];
				if (x - a[i - 1] < y)
				
					ans = ans + (2 * last + 1 + x - a[i - 1]) * (x - a[i - 1]) / 2;
					last = last + x - a[i - 1];
				
				else
				
					ans = ans + (b[i] + 1) * b[i] / 2;
					last = b[i];
				
			
			else
			
				ans = ans + (b[i] + 1) * b[i] / 2;
				last = b[i];
			
		
		cout << ans << endl;
	
	return 0;

以上是关于Educational Codeforces Round 121 (Rated for Div. 2) (A ~ C)的主要内容,如果未能解决你的问题,请参考以下文章

Educational Codeforces Round 7 A

Educational Codeforces Round 7

Educational Codeforces Round 90

Educational Codeforces Round 33

Codeforces Educational Codeforces Round 54 题解

Educational Codeforces Round 27