This is a chanllenging problem on codeforces with a diffcuilt score of 1400.
It presents a intressting chanllege that can be solved by using the principle of constructive.
point 1:There are no answers if m < n - 1.
point 2:There are no answers if m > (n - 1) * 2
Returning to the constructive part, If m == n - 1, we should set 0 as the leading number of the sequence.Otherwise, we can set 1 as the leading number, followed by 10,until the number of m is equal to the number of n. After that, we simply output 10 until the numbers become 0.
https://codeforces.com/problemset/problem/401/C
void solve(){
int n, m;
cin >> n >> m;
if (m < n - 1 || m > (n + 1) * 2){
cout << -1 << '\n';
}
else if (m == n - 1){
while (n -- >= 2){
cout << "01";
}
cout << 0;
}
else{
while (n > 0 && m > 0){
if (m > n){
cout << "110";
m -= 2;
n -= 1;
}
else{
cout << "10";
m --;
n --;
}
}
while (m --){
cout << 1;
}
}
}
标签:set,cout,point,leading,There,number,Team
From: https://www.cnblogs.com/yxcblogs/p/18045691