当前位置: 首页 > article >正文

CF 1894A 学习笔记 思维 题意理解分析

原题

A. Secret Sport

time limit per test

3 seconds

memory limit per test

512 megabytes

input

standard input

output

standard output

Let's consider a game in which two players, A and B, participate. This game is characterized by two positive integers, 𝑋� and 𝑌�.

The game consists of sets, and each set consists of plays. In each play, exactly one of the players, either A or B, wins. A set ends exactly when one of the players reaches 𝑋� wins in the plays of that set. This player is declared the winner of the set. The players play sets until one of them reaches 𝑌� wins in the sets. After that, the game ends, and this player is declared the winner of the entire game.

You have just watched a game but didn't notice who was declared the winner. You remember that during the game, 𝑛� plays were played, and you know which player won each play. However, you do not know the values of 𝑋� and 𝑌�. Based on the available information, determine who won the entire game — A or B. If there is not enough information to determine the winner, you should also report it.

Input

Each test contains multiple test cases. The first line contains a single integer 𝑡� (1≤𝑡≤104)(1≤�≤104) - the number of test cases. The description of the test cases follows.

The first line of each test case contains an integer 𝑛� (1≤𝑛≤20)(1≤�≤20) - the number of plays played during the game.

The second line of each test case contains a string 𝑠� of length 𝑛�, consisting of characters 𝙰A and 𝙱B. If 𝑠𝑖=𝙰��=A, it means that player A won the 𝑖�-th play. If 𝑠𝑖=𝙱��=B, it means that player B won the 𝑖�-th play.

It is guaranteed that the given sequence of plays corresponds to at least one valid game scenario, for some values of 𝑋� and 𝑌�.

Output

For each test case, output:

  • 𝙰A — if player A is guaranteed to be the winner of the game.
  • 𝙱B — if player B is guaranteed to be the winner of the game.
  • ?? — if it is impossible to determine the winner of the game.

Example

input

Copy

 

7

5

ABBAA

3

BBB

7

BBAAABA

20

AAAAAAAABBBAABBBBBAB

1

A

13

AAAABABBABBAB

7

BBBAAAA

output

Copy

A
B
A
B
A
B
A

Note

In the first test case, the game could have been played with parameters 𝑋=3�=3, 𝑌=1�=1. The game consisted of 11 set, in which player A won, as they won the first 33 plays. In this scenario, player A is the winner. The game could also have been played with parameters 𝑋=1�=1, 𝑌=3�=3. It can be shown that there are no such 𝑋� and 𝑌� values for which player B would be the winner.

In the second test case, player B won all the plays. It can be easily shown that in this case, player B is guaranteed to be the winner of the game.

In the fourth test case, the game could have been played with parameters 𝑋=3�=3, 𝑌=3�=3:

  • In the first set, 33 plays were played: AAA. Player A is declared the winner of the set.
  • In the second set, 33 plays were played: AAA. Player A is declared the winner of the set.
  • In the third set, 55 plays were played: AABBB. Player B is declared the winner of the set.
  • In the fourth set, 55 plays were played: AABBB. Player B is declared the winner of the set.
  • In the fifth set, 44 plays were played: BBAB. Player B is declared the winner of the set.

In total, player B was the first player to win 33 sets. They are declared the winner of the game.

代码

#include<bits/stdc++.h>
using namespace std;

int main()
{
	int t;
	scanf("%d",&t);
	
	while(t--)
	{
		int n;
		scanf("%d",&n);
		string s;
		cin>>s;
		printf("%c\n",s[n-1]);
	}
	
	return 0;
}

原题链接

传送门icon-default.png?t=N7T8https://codeforces.com/contest/1894/problem/A 总结

参考

1.官方题解

2.赛时rank 1代码

思考

1.题目的意思有点难懂,英文要一个一个单词慢慢看,仔细去理解英文句子背后的意思,这个题目的意思是说,A和B两个人进行一场比赛,比赛有多个回合(sets),每一个回合有多场(plays),一个回合结束的标志是某一个人赢得X场(plays),某一个人赢得Y个回合,整个比赛结束

2.输入一个数字n,表示总共进行了多少场比赛,然后输入一个字符串,表示每一场比赛的胜利者。

3.我们最后需要输出谁是最终的胜利者,A/B/?,问号表示不能确定谁是最终的胜利者。

4.最后一场的胜利者就是最终的胜利者,因为假设最后一场不能决定胜负,就不会进行最后一场比赛,所以说,代码非常简单,输出最后一场的胜利者即可,也就是字符串的最后一个字符

 

 


http://www.kler.cn/a/137475.html

相关文章:

  • 2023年软件团队的六款最佳API文档工具
  • Spring-IOC-@Value和@PropertySource用法
  • MongoDB之索引和聚合
  • SQL基础理论篇(八):视图
  • 阿里云服务器3M固定带宽够用吗?
  • 股票基础数据(二)
  • 全网最全jmeter接口测试/接口自动化测试看这篇文章就够了:跨线程组传递jmeter变量及cookie的处理
  • 渲染器——简单Diff算法
  • 政府采购变数大,联想还值不值得代理渠道商们“跟”?
  • 用javascript方法,禁止用户操作页面
  • Apache Doris安装部署
  • 【JavaSE】-4-循环结构
  • 【CSH 入门基础 10 -- csh 设置 脚本执行的优先级】
  • UE4基础篇十六:自定义 EQS 生成器
  • uniapp-轮播图点击预览功能
  • re 2021强网杯复现
  • Java8Stream快速使用
  • IOS输入框聚焦会把内容区域顶起
  • 海外IP代理科普——API代理
  • matlab求矩阵的伪逆或者负二分之一次方