Codeforces Round 640 (Div. 4) F

Problem - F - Codeforces

思路:

把每种情况都考虑到即可(具体看代码)

注意:

三个数都是有可能为0的,但是不会全为0

代码:

#include<bits/stdc++.h>
using LL = long long;

void solve(){
	// I know you are here
	// Thank you for your appreciation
	
	int a, b, c;
	std::cin >> a >> b >> c;
	std::string ans;
	if(a == 0) {
		if(b == 0) {   //此时c一定不为0
			for(int i = 1; i <= c + 1; i++) {
				ans += '1';
			}
		}
		else {  //否则讨论b的奇偶性
			if(b & 1) {  //当b是奇数时,先给答案填入一个0,最终第二类子串解决完后结尾一定是1
				ans += '0';
				int op = 1;
				for(int i = 1; i <= b; i++) {
					if(op & 1) ans += '1';
					else ans += '0';
					op++;
				}
			}
			else {  //当b为偶数时,先给答案填入一个1,最终第二类子串解决完后结尾一定是1
				ans += '1';
				int op = 1;
				for(int i = 1; i <= b; i++) {
					if(op & 1) ans += '0';
					else ans += '1';
					op++;
				}
			}
			for(int i = 1; i <= c; i++) ans += '1'; //解决第三类子串即可
		}
	}
	else {
		for(int i = 1; i <= a + 1; i++) {  //首先解决第一类子串
			ans += '0';
		}
		if(b) {  //若b为零则c一定也为零,因为题目保证答案一定存在
			if(b & 1) { //当b为奇数时,将第二类子串解决完即可
				int op = 1;
				for(int i = 1; i <= b; i++) {
					if(op & 1) ans += '1';
					else ans += '0';
					op++;
				}
				for(int i = 1; i <= c; i++) {  //解决第三类子串
					ans += '1';
				}
			}
			else { //当b为偶数时,解决第二类子串,但是要剩下一个
				int op = 1;
				for(int i = 1; i < b; i++) {
					if(op & 1) ans += '1';
					else ans += '0';
					op++;
				}
				for(int i = 1; i <= c; i++) { //解决第三类子串
					ans += '1';
				}
				ans += '0'; //把第二类子串剩下那一个补上
			}
		}
	}
	std::cout << ans << "\n";
}
int main(){
	std::ios::sync_with_stdio(false);
	std::cin.tie(0);std::cout.tie(0);
	
	int _;
	std::cin >> _;
	while(_--){
		solve();
	}
	return 0;
}

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值