P8536 「Wdoi-2」幻胧月睨 题解

· · 题解

Description

给你一个01字符串 ss_i=1 时, \forall 1\le j\le i-1,a_i>a_j , s_i =0 时, a_i 不满足上述条件,求任一满足条件的 a 数列。

Solution

设字符串 s 中有 x 个0, y 个1,则 \forall s_i=1,a_i=n-i+1 ,即升序,既能保证 a_i>a_j ,也能保证 a_{i_1}<a_{i_2} ,再来看

## _Code_ ```cpp int t; int n; int a[100100]; string s; int main(){ cin>>t; while(t--){ int cnt=0,tot=0; cin>>n; cin>>s; for(int i=1;i<=n;i++){ if(s[i-1]=='1') tot++; // cout<<a[i]; } tot=n-tot+1; //不要忘了加一 cnt=tot-1; for(int i=1;i<=n;i++){ if(s[i-1]=='0'){ cout<<cnt<<" "; cnt--;//递减 } else{ cout<<tot<<" "; tot++;//递增 } } cout<<endl; } return 0; } ``` #### 完结撒花!!