# 问题 J: Juggling Troupe

## 题目描述

At the national centre for computing and advanced circus skills, technical demonstrations by students are strongly encouraged.
A troupe of n novice performers are at this very moment arrayed in a row attempting to put on a juggling show. Unfortunately, none of them are very conﬁdent in their craft, and they are struggling. Thus, as soon as an opportunity presents itself, they will try to reduce their part in the performance to make the task easier.
Whenever a juggler has more than one ball in their possession, they will throw one ball to each of their neighbours. In the case that a juggler does not have a neighbour in some direction, they will simply throw the ball offstage instead. Everybody throws their juggling balls simultaneously. The show ends when no juggler has more than one ball.
As a member of the audience, you are not impressed by this performance. However, you do wonder how many balls each of the jugglers will have left at the end of the show.

## 输入

The input consists of:
• One line with a string s of length n (1 ≤ n ≤ 106 ) over the characters 0, 1 and 2. The ith character in s represents the number of juggling balls initially held by the ith person.

## 输出

Output a string s of length n over the characters 0 and 1, the ith giving the number of juggling balls the ith person has at the end of the show.

## 样例输入

12100212


## 样例输出

10111111


AC代码：
#include<bits/stdc++.h>
#define lowbit(x) (x&-x)
#define gcd(a,b) __gcd(a,b)
#define mset(a,x) memset(a,x,sizeof(a))
#define FIN freopen("input","r",stdin)
#define FOUT freopen("output","w",stdout)
const int INF=0x3f3f3f3f;
const double pi=acos(-1.0);
const double eps=1e-6;
const int MAX=1e5+10;
const int mod=1e9+7;
typedef long long ll;
using namespace std;
inline ll lcm(ll a,ll b){return a/gcd(a,b)*b;}
inline ll qpow(ll a,ll b){ll r=1,t=a; while(b){if(b&1)r=(r*t)%mod;b>>=1;t=(t*t)%mod;}return r;}
inline ll inv1(ll b){return qpow(b,mod-2);}
inline ll inv2(ll b){return b==1?1:(mod-mod/b)*inv2(mod%b)%mod;}
inline ll exgcd(ll a,ll b,ll &x,ll &y){if(!b){x=1;y=0;return a;}ll r=exgcd(b,a%b,y,x);y-=(a/b)*x;return r;}
int dir[4][2]={0,1,1,0,0,-1,-1,0};
char str[1000005];
int temp[1000005];
int main (){
scanf ("%s",str+1);
int n=strlen(str+1);
set<int> S;
int Index=0;
S.insert(0); S.insert(n+1);
for (int i=1;i<=n;i++){
if(str[i]=='0') S.insert(i);
if(str[i]=='2') temp[Index++]=i;
}
for (int i=0;i<Index;i++){
set<int>::iterator it=S.lower_bound(temp[i]);
int right=*it;
int left=*--it;
if(left!=0) str[left]='1',S.erase(left);
if(right!=n+1) str[right]='1',S.erase(right);
str[left+right-temp[i]]='0';
S.insert(left+right-temp[i]);
if(str[temp[i]]!='0') str[temp[i]]='1';
}
for (int i=1;i<=n;i++)
if(str[i]=='0') putchar('0');
else putchar('1');
putchar('\n');
return 0;
}


• 广告
• 抄袭
• 版权
• 政治
• 色情
• 无意义
• 其他

120