Ice and Fire - 洛谷 | 计算机科学教育新生态 (luogu.com.cn)
求1~i中有多少个数有可能活到最后
在一段连续的0或者连续的1中只能有1个存活下来
连续段前面通过合理的安排 每个数 都有可能活到最后,
#include <bits/stdc++.h>
#include <iostream>
#include<unordered_map>
#include<unordered_set>
#define x first
#define y second
#define ios ios::sync_with_stdio(0),cin.tie(0),cout.tie(0);
using namespace std;
typedef long long LL ;
typedef unsigned long long ULL ;
typedef pair<int,int> PII ;
typedef pair<LL,int> PLI ;
const int N = 1e9;
int n,m,q;
inline void solve()
{
int n;string s;
cin >> n >> s;
int cnt0=0,cnt1=0;
for(int i=0;i < n-1 ;i ++ )
{
if(s[i] == '0'){
cnt1= 0;cnt0 ++ ;
}
else
{
cnt1 ++ ;cnt0=0;
}
cout << i + 1 - max(cnt0,cnt1) + 1 << " ";
}
cout << endl;
}
signed main()
{
ios
int T=1;
cin>>T;
while(T -- )
{
solve();
}
return 0;
}