Educational Codeforces Round 86 (Rated for Div. 2) 题解

 白给题1

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
int main () {
	ios::sync_with_stdio(false);
	cin.tie(0);
	int t;
	cin >> t;
	while(t--) {
		ll x, y;
		ll a, b;
		cin >> x >> y >> a >> b;
		ll ans = 0;
		ans = abs(x - y) * a + min(x, y) * min(b, 2 * a);
		cout << ans << endl;
	}
}

 

 白给题2

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
int main () {
	ios::sync_with_stdio(false);
	cin.tie(0);
	int t;
	cin >> t;
	bool endd = 0;
	while(t--) {
		endd = 0;
		string s;
		cin >> s;
		if(s.size() == 1) {
			cout << s << endl;
			continue;
		}
		//为1的情况
		for(int i = 0; i < s.size() - 1; ++i) {
			if(s[i] != s[i + 1]) {
				break;
			}
			if(i == s.size() - 2) {
				cout << s << endl;
				endd = 1;
			}
		}
		if(endd) {
			continue;
		}
		//为2
		string ans = "";
		for(int i = 0; i < s.size() - 1; ++i) {
			string str;
			stringstream stream;
			stream << s[i];
			str = stream.str();
			ans += str;
			if(s[i] == '1' && s[i + 1] == '1') {
				ans += "0";
			}
			if(s[i] == '0' && s[i + 1] == '0') {
				ans += "1";
			}
		}
		string str;
		stringstream stream;
		stream << s[s.size() - 1];
		str = stream.str();
		ans += str;
		cout << ans << endl;
	}
}

 

 思维题找循环规律

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
int f[100010];
ll getAns(ll sb, int t) {
	return f[t - 1] * (sb / t) + f[sb % t];
	//利用循环的特性进行求解
}
int main () {
	ios::sync_with_stdio(false);
	int t;
	cin >> t;
	while(t--) {
		int a, b, q;
		cin >> a >> b >> q;
		int temp = a * b;
		for(int i = 1; i < temp; ++i) {
			f[i] = f[i - 1];
			if(i % a % b != i % b % a) {
				f[i]++;
			}
		}
		while(q--) {
			ll l, r;
			cin >> l >> r;
			cout << getAns(r, temp) - getAns(l - 1, temp) << " ";
		}
		putchar(10);
	}
}

 后面的题心情好再更新。。。学计组洋文去了

作者:LightAc
出处:https://www.cnblogs.com/lightac/
联系:
Email: dzz@stu.ouc.edu.cn
QQ: 1171613053
本文版权归作者和博客园共有,欢迎转载,但未经作者同意必须保留此段声明,且在文章页面明显位置给出原文链接,否则保留追究法律责任的权利。
原文地址:https://www.cnblogs.com/lightac/p/12788118.html