0
点赞
收藏
分享

微信扫一扫

Codeforces Round #786 (Div. 3) Editorial(A/B/C/D)待补

彪悍的鼹鼠 2022-05-04 阅读 88
c++

A.

int main() {
	IOS;
	// freopen("P1908_6.in","r",stdin);//读入数据
	// freopen("P1908.out","w",stdout); //输出数据
	int t;
	cin >> t;
	while(t--){
		ll x, y;
		cin >> x >> y;
		if(y < x || y % x)
			cout << "0 0" << endl;
		else {
			cout << "1 " << y / x << endl;
		}
	}
	return 0;
}

B.

int main() {
	IOS;
	// freopen("P1908_6.in","r",stdin);//读入数据
	// freopen("P1908.out","w",stdout); //输出数据
	int t;
	cin >> t;
	while(t--){
		//转换进制
		string s;
		cin >> s;
		int ans = (s[0] - 'a') * 26 + (s[1] - 'a');
		if(s[1] < s[0])
			++ans;
		ans -= (s[0] - 'a');
		cout << ans << endl;
	}
	return 0;
}

C.

ll a[55];
void bitt(){
	a[0] = 1;
	a[1] = 2;
	for (int i = 2; i <= 50; ++i){
		a[i] = 2 * a[i - 1];
	}
}

int main() {
	IOS;
	// freopen("P1908_6.in","r",stdin);//读入数据
	// freopen("P1908.out","w",stdout); //输出数据
	int t;
	bitt();
	cin >> t;
	while(t--){
		//不该面向样例编程
		string s, t;
		cin >> s >> t;
		bool flag = true;
		for (int i = 1; i < 26; ++i){
			char c = 'a' + i;
			if(t.find(c) != string::npos) {
				flag = false;
				break;
			}
		}
		if(flag) {//全是a
			if(t.size() == 1){
				cout << 1 << endl;
			}
			else
				cout << -1 << endl;
		}
		else {
			//有其它
			if(t.find('a') == string::npos){
				if(s.size() == 1)
					cout << 2 << endl;
				else 
					cout << a[s.size()] << endl;//啊这里怎么算啊
			}
			else {
				cout << -1 << endl;
			}
		}
	}
	return 0;
}

D.

下次可以猜正常一点的结论
新知识:is_sorted()

一定要去验证自己的想法,模拟看看

在这里插入图片描述

int main() {
	IOS;
	int t;
	cin >> t;
	while(t--){
		int n;
		cin >> n;
		int a[maxn];
		for (int i = 1; i <= n; ++i){
			cin >> a[i];
		}
		int s = 1;
		if (n % 2 == 1)
			s = 2;//啊这里好神奇,建议自己模拟21435
		for (int i = s; i < n; i += 2){
			if(a[i] > a[i + 1])
				swap(a[i], a[i + 1]);
		}
		/*
		这里还有几个对比方法
		1.is_sorted
		2.创个b数组,排序后和移动的a比较
		3.直接看a[i]大不大于a[i + 1]
		*/
		cout << (is_sorted(a + 1, a + n + 1) ? "YES" : "NO") << endl;
	}
	return 0;
}
举报

相关推荐

0 条评论