CF1774C Ice and Fire
题目描述
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 $ 0 $ or $ 1 $ . When two players fight in a specific environment, if its type is $ 0 $ , the player with a lower temperature value in this environment always wins; if it is $ 1 $ , the player with a higher temperature value in this environment always wins. The types of the $ n-1 $ environments form a binary string $ s $ with a length of $ n-1 $ .
If there are $ x $ players participating in the game, there will be a total of $ x-1 $ battles, and the types of the $ x-1 $ environments will be the first $ x-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 $ s_i $ .
For each $ x $ from $ 2 $ 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?
分析
这道题需要手玩数据。
我们发现,01 串结尾的连续个相同字符,并不影响游戏结果,也就是不会增加可能的人数。因为场地是按顺序使用的,设结尾连续长度为 \(l\),我们经过前 \(n - 1 - l\) 场比赛之后的剩余人数为 \(t\) 集合,那么剩下的连续字符一定会选出 \(t\) 中的最大值或最小值。
那么可能情况的改变就在连续段之前,如果最后连续段是 \(0\) 最后会选出最小值,则前面需要删掉最小值才能改变最终结果。
#include <bits/stdc++.h>
#define rei register int
#define ll long long
#define IOS ios::sync_with_stdio(false); cin.tie(0); cout.tie(0);
#define rep(i, s, n, c) for (register int i = s; i <= n; i+=c)
#define repd(i, s, n, c) for (register int i = s; i >= n; i-=c)
#define CHECK cout<<"WALKED"<<endl;
inline int read(){int x=0,f=1;char ch=getchar();while(ch<'0'||ch>'9'){if(ch=='-')f=-1;ch=getchar();} while(ch>='0' && ch<='9')x=(x<<3)+(x<<1)+ch-'0',ch=getchar();return x*f;}
#define pb push_back
#define ls id<<1
#define rs id<<1|1
const int INF = INT_MAX;
long long binpow(long long a, long long b, ll mod){long long res = 1; while (b > 0){if (b & 1) res = res * a % mod;a = a * a % mod; b >>= 1; } return res;}
using namespace std;
int main()
{
int T = read();
while (T--) {
int n, k = 1; string s;
cin >> n >> s;
s = "**" + s;
cout << 1 << " ";
for (int i = 3; i < (int)s.size(); i++) {
if (s[i] == s[i - 1])
k++;
else
k = 1;
printf("%d ", i - k);
}
printf("\n");
}
return 0;
}
标签:ch,player,Fire,CF1774C,environment,players,int,Ice,define
From: https://www.cnblogs.com/CYLSY/p/17030012.html