Ice and Fire time limit per test 1 second memory limit per test 256 megabytes input standard input output standard output
Little09 and his friends are playing a game. There are n players, and the temperature value of the player i is i.
The types of environment are expressed as 00 or 11. When two players fight in a specific environment, if its type is 00, the player with a lower temperature value in this environment always wins; if it is 11, the player with a higher temperature value in this environment always wins. The types of the n−1−1 environments form a binary string s with a length of n−1−1.
If there are x players participating in the game, there will be a total of x−1−1 battles, and the types of the x−1−1 environments will be the first x−1−1 characters of s. While there is more than one player left in the tournament, choose any two remaining players to fight. The player who loses will be eliminated from the tournament. The type of the environment of battle i is si.
For each x from 22 to n, answer the following question: if all players whose temperature value does not exceed x participate in the game, how many players have a chance to win?
InputEach test contains multiple test cases. The first line contains a single integer t (1≤t≤1031≤≤103) — the number of test cases. The description of the test cases follows.
The first line of each test case contains a single integer n (2≤n≤2⋅1052≤≤2⋅105) — the number of players.
The second line of each test case contains a binary string s with a length n−1−1.
It is guaranteed that the sum of n over all test cases does not exceed 3⋅1053⋅105.
OutputFor each test case output n−1−1 integers — for each x from 22 to n, output the number of players that have a chance to win.
Example input Copy 2 4 001 4 101 output Copy1 1 3 1 2 3Note
In the first test case, for x=2=2 and x=3=3, only the player whose temperature value is 11 can be the winner. For x=4=4, the player whose temperature value is 2,3,42,3,4 can be the winner.
#include <bits/stdc++.h> #define int long long using namespace std; const int N=1e6+10,mod=1e9+7; string s; int n,t,a[N],f[N],res,num,ans,m; bool vis[N]; signed main() { std::ios::sync_with_stdio(false),cin.tie(0),cout.tie(0); cin>>t; while(t--){ cin>>n>>s; int one=0,zero=0,res=1; for(int i=0;i<s.size();i++){ if(s[i]=='1') one++,zero=0; else one=0,zero++; cout<<i+2-max(one,zero)<<" "; } } return 0; }
标签:temperature,players,Fire,Ice,environment,player,value,test From: https://www.cnblogs.com/o-Sakurajimamai-o/p/17572945.html