Puzzle From the Future(思维+贪心)

https://codeforces.com/contest/1474

思路:高位优先放大的数,下一位如果放大数和上一位相同,就放小数。

#include<iostream>
#include<vector>
#include<queue>
#include<cstring>
#include<cmath>
#include<map>
#include<set>
#include<cstdio>
#include<algorithm>
#define debug(a) cout<<#a<<"="<<a<<endl;
using namespace std;
const int maxn=1e5+1000;
typedef long long LL;
char a[maxn];
int main(void)
{
  cin.tie(0);std::ios::sync_with_stdio(false);
  LL t;cin>>t;
  while(t--){
    LL n;cin>>n;
    for(LL i=1;i<=n;i++) cin>>a[i];
    LL last=a[1]+1;
    for(LL i=1;i<=n;i++){
        if(i==1){
            cout<<1;
        }
        else{
            if(a[i]+1==last){
                cout<<0;
                last=a[i];
            }
            else{
                cout<<1;
                last=a[i]+1;
            }
        }
    }
    cout<<endl;
  }
return 0;
}

猜你喜欢

转载自blog.csdn.net/zstuyyyyccccbbbb/article/details/112859212