首页 > 其他分享 >Ice and Fire

Ice and Fire

时间:2023-01-09 19:12:23浏览次数:62  
标签:temperature players Fire Ice environment player value test

题目链接

题目描述:

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?

输入描述:

Each test contains multiple test cases. The first line contains a single integer \(t\) \((1≤t≤10^3)\) — 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⋅10^5)\) — the number of players.

The second line of each test case contains a binary string \(s\) with a length \(n−1\).

It is guaranteed that the sum of \(n\) over all test cases does not exceed \(3⋅10^5\).

输出描述:

For each test case output \(n−1\) integers — for each \(x\) from \(2\) to \(n\), output the number of players that have a chance to win.

样例:

input:

2
4
001
4
101

output:

1 1 3
1 2 3

Note:

In the first test case, for \(x=2\) and \(x=3\), only the player whose temperature value is \(1\) can be the winner. For \(x=4\), the player whose temperature value is \(2,3,4\) can be the winner.

AC代码:

#include <bits/stdc++.h>

using namespace std;

const int N = 2e5 + 10;

int T;
int n;
int a[2];

// 需要判断一下后缀有多少个连续的1或者0
// 假设有n个人,需要n - 1场战斗,s字符串最后有x个连续的1
// 1 ~ x中没有人可以活,因为最后x场战斗必须要有编号比他小人
// 而最好的情况就是第x个人,而第x个人也只有x - 1个编号比他小的人,x - 1比x小所以最后x肯定会死掉
// 而x + 1 ~ n中都有机会活下去,在x + 1 ~ n中选择两个人活下去,而x + 1 ~ n的其他人都在n - x - 2场战斗中死掉
// 因为第x - 1个字符必定是0,则所以在第n - x - 1次战斗中选择让两个人中的一个人和1战斗,1必获胜
// 那么最后剩下的那一个人成为了编号最大的一个人,那么在剩下的x场战斗中那个人必然获胜,而显然在x - 1 ~ n中每个人都可以成为最后剩下的那个人
// 后缀连续为0的情况同理
// 假设f是连续后缀的最大长度
// 所以综上所述i场战斗最后有机会获胜的人是i - fi + 1
// 而i - fi实际上也就是连续后缀前面的字符的个数
void solve()
{
	cin >> n;

	string s;
	cin >> s;

	a[0] = a[1] = 0;

	for(int i = 0; i < n - 1; i ++)
	{
		a[s[i] - '0'] = i + 1;

		if(s[i] == '0')
		{
			cout << a[1] + 1 << ' ';
		}
		else
		{
			cout << a[0] + 1 << ' ';
		}
	}

	cout << '\n';
}

int main()
{
	ios::sync_with_stdio(false), cin.tie(0), cout.tie(0);

	cin >> T;

	while(T --)
		solve();

	return 0;
}

标签:temperature,players,Fire,Ice,environment,player,value,test
From: https://www.cnblogs.com/KSzsh/p/17037844.html

相关文章

  • Centos 安装 Dzzoffice 并使用 onlyoffice
    1:安装lnmp首先在系统中安装nginx、mysql、php2:下载安装包https://gitee.com/zyx0814/dzzoffice/releases 3:解压文件将下载的安装包解压到网站根目录4:设置dzzoffice......
  • 编辑可执行service weblogic start命令启动weblogic服务脚本
    转至:https://blog.csdn.net/VickHUC/article/details/88416046《一》创建weblogic文件,并编辑vi/etc/init.d/weblogic加入下面内容,如果是粘贴进去,切记要检查开头和末......
  • AZ-500 Lab-configure a lock for the app service plan
    由于微软Azure平台界面一直都在变,所以通过考试的关键,是真正理解lab题要表达的意思,不要死记硬背。SIMULATION-Youneedtopreventadministratorsfromperformingacciden......
  • 【linux】linux Centos8系统,防火墙配置常用命令,systemctl 和firewall
    本文环境:Linux系统CentOS8.264bitCentOS7版本及以上版本较centos6有较大改动,例如:采用systemctl命令来开启service,它是服务管理中主要的工具,融合了之前service和chkconf......
  • SSM的详细整合(dao,service,controller及各种配置)
    配置确实挺多的,我这个也是只包含了部分常用配置(如果大家有需要可以后续更新所有配置):数据源的连接,自动创建Mapper代理对象归于容器,事务的使用AOP(切面编程)的基本配置视图......
  • office word打开网页超链接失败 提示 组织策略阻止我们......
    官方offic指导修改注册表。建议先注册表备份,虽然我没用上。新建txt文档,粘贴下面代码,保存为.reg。然后双击运行。我用了,完美解决“officeword打开网页超链接失败提示组织......
  • Firepower IPS POC测试
    测试环境拓扑如下:Step1:创建IPS策略,如下图:Step2:将IPS策略调用,如下图:Step3:进行流量安全分析,查看安全日志,如下图:    ......
  • JavaScript学习笔记—数组方法slice和splice
    (1)slice()方法定义:从已有的数组返回选定的元素语法:arrayObject.slice(start,end)start:必选。截取开始位置的索引,包含开始索引end:可选。截取结束位置的索引,不包含结......
  • JS中splice的具体使用
    介绍splice在处理字符串时有许多的使用技巧,比如对数组任意位置添加,在任意位置删除指定长度,任意位置进行替换删除splice在删除时接收两个参数,第一个参数为起始位置,第二个......
  • IDEA通过Services界面管理多个SpringBoot应用
    问题以前使用老版本IDEA时,如果一个Project下有多个基于SpringBoot的module,本地启动时需要一个个点击Debug或者Run来启动,无法一键启动和停止多个应用。解决新版本的IDEA......