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

 

 

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:/a/172728.html

如若内容造成侵权/违法违规/事实不符,请联系我们进行投诉反馈qq邮箱809451989@qq.com,一经查实,立即删除!

相关文章

Spring源码-5.aop代理

&#x1f44f;作者简介&#xff1a;大家好&#xff0c;我是爱吃芝士的土豆倪&#xff0c;24届校招生Java选手&#xff0c;很高兴认识大家&#x1f4d5;系列专栏&#xff1a;Spring源码、JUC源码&#x1f525;如果感觉博主的文章还不错的话&#xff0c;请&#x1f44d;三连支持&…

4.2、Linux进程(1)

个人主页&#xff1a;Lei宝啊 愿所有美好如期而遇 目录 基本概念 描述进程-PCB task_struct-PCB的一种 task_struct内容分类 查看进程 通过系统调用获取进程标识符 前言 进入进程前&#xff0c;我建议读一读这两篇文章&#xff0c;他们都是进程的前导知识。 操作系统…

Joern安装与使用

环境准备 Joern需要在Linux环境中运行&#xff0c;所以在Windows系统中需要借助WSL或虚拟机安装。 JDK安装 Joern的运行需要JAVA环境的支持&#xff0c;本次采用的是JDK17&#xff0c;其他版本建议看一下Joern官方文档。 apt install openjdk-17-jre-headless 配置JAVA环境变…

shell脚本之条件语句

条件语句 linux测试 test 测试 测试表达式是否成立&#xff08;用echo $? 检测是否正确&#xff09; 语法&#xff1a;test [选项] [文件名] 选项作用-e测试文件是否存在-r查看文件有无读的权限-d测试是否为目录-f测试是否为文件-w测试当前用户有无写的权限-x测试是否有执…

EANet:用于医学图像分割的迭代边缘注意力网络

EANet: Iterative edge attention network for medical image segmentation EANet&#xff1a;用于医学图像分割的迭代边缘注意力网络背景贡献实验方法Dynamic scale-aware context module&#xff08;动态规模感知上下文模块&#xff09;Edge attention preservation module&a…

【Java】java | CacheManager | redisCacheManager

一、说明 1、查询增加缓存&#xff0c;使用Cacheable注解 2、项目中已经用到了ehcache&#xff0c;现在需求是两个都用 二、备份配置 1、redisConfig增加代码 Bean("redisCacheManage")Primarypublic CacheManager redisCacheManager(RedisConnectionFactory fact…

Matlab通信仿真系列——图形处理函数

微信公众号上线&#xff0c;搜索公众号小灰灰的FPGA,关注可获取相关源码&#xff0c;定期更新有关FPGA的项目以及开源项目源码&#xff0c;包括但不限于各类检测芯片驱动、低速接口驱动、高速接口驱动、数据信号处理、图像处理以及AXI总线等 本节目录 一、plot函数 (1)绘制一…

SystemV

一、共享内存 1、直接原理 进程间通信的本质是&#xff1a;先让不同的进程&#xff0c;看到同一份资源&#xff01;&#xff01; 我们要把这句话奉若圭臬一般 到了共享内存了支持双向通信能读也能写&#xff0c;但是一般都是一个读一个写 要想通信先看到同一个份资源&#xff0…

Lifecyle的原理

1、Lifecycle是典型的观察者模式&#xff0c;被观察者的继承关系如上图所示。 2、LifeCycleRegistry是Lifecycle的子类。 3、观察者通过LifeCycle对象的addObserver注册监听生命周期的变化&#xff0c;通过removeObserver移除监听生命周期的变化。 4、Activity或Fragment的生命…

HDFS的Shell操作

文章目录 一、HDFS的Shell介绍二、了解HDFS常用Shell命令&#xff08;一&#xff09;三种Shell命令方式&#xff08;二&#xff09;FileSystem Shell文档&#xff08;三&#xff09;常用HDFS的Shell命令 三、HDFS常用命令操作实战&#xff08;一&#xff09;创建目录&#xff0…

深度学习之基于Pytorch的昆虫分类识别系统

欢迎大家点赞、收藏、关注、评论啦 &#xff0c;由于篇幅有限&#xff0c;只展示了部分核心代码。 文章目录 一项目简介系统架构技术亮点 二、功能三、系统四. 总结 一项目简介 # 深度学习基于 Pytorch 的昆虫分类识别系统介绍 深度学习在图像分类领域取得了显著的成就&#…

windows上 adb devices有设备 wsl上没有

终于解决了&#xff01;&#xff01;&#xff01;&#xff01; TAT&#xff0c;尝试了很多种办法。 比如WSL中的adb和Windows中的adb版本必须一致&#xff0c;一致也没用&#xff0c;比如使用 ln 建立链接也没用。 这个解决办法的前提是windows中的abd是好用的。 ●在windows…

计算机显示msvcp140.dll丢失的解决方法,实测有效的5个方法分享

在日常的电脑操作中&#xff0c;常常遭遇某些错误讯息&#xff0c;如“缺少xxx.dll文件”&#xff0c;这些dll文件即为动态链接库文件&#xff0c;内含诸多可执行的程序码及数据。当启动某款应用时&#xff0c;系统将会自动调用与其相关的dll文件&#xff0c;其中msvcp140.dll便…

pycharm 控制台中文乱码处理

今天使用pycharm&#xff0c;发现控制台输出又中文乱码了&#xff0c;看网上很多资料说把编码改为UTF-8&#xff0c;设置为并未生效&#xff0c;特此在此记录下本地设置。 1. 修改文件编码&#xff1a;Setting -> Editor ->File Encodings,修改配置如下&#xff1a; 2. …

深入了解Java 8 新特性:Stream流的实践应用(一)

阅读建议 嗨&#xff0c;伙计&#xff01;刷到这篇文章咱们就是有缘人&#xff0c;在阅读这篇文章前我有一些建议&#xff1a; 本篇文章大概一万多字&#xff0c;预计阅读时间长需要10分钟&#xff08;不要害怕字数过多&#xff0c;其中有一大部分是示例代码&#xff0c;读起…

Kotlin 核心语法,为什么选择Kotlin ?

Kotlin 是一个基于 JVM 的新的编程语言&#xff0c;由 JetBrains 开发。与Java相比&#xff0c;Kotlin的语法更简洁、更具表达性&#xff0c;而且提供了更多的特性。 Kotlin是使用Java开发者的思维被创建的&#xff0c;Intellij作为它主要的开发IDE。对于 Android开发者&#…

用百度AI大模型给头像换风格

心血来潮想尝试尝试AI小应用&#xff0c;给图片加个风格&#xff08;例如微信头像&#xff09;&#xff0c;于是有了这篇简短的教程 目录 1. 领取免费资源2. 在应用列表创建应用3. 在线API调试4. 效果对比 1. 领取免费资源 网站&#xff1a;百度智能云 百度给提供了很多AIGC的…

手搓js轮播图_JavaScript进阶

手搓js轮播图 逻辑解析html结构图片切换方法圆点导航切换效果左右箭头点击切换圆点导航点击切换自动播放&#xff0c;介入暂停 完整代码 逻辑解析 css的样式我就不再进行讲述&#xff0c;如果有需求可以评论区告诉我&#xff0c;我再出一篇文章进行详细讲解 js轮播图最主要的核…

执行npm的时候报权限问题的解决方案

我们在执行npm操作的过程中&#xff0c;会出现以下权限问题&#xff0c;解决方案: 管理员身份 运行cmd 切换目录到要执行命令的文件下 再进行npm操作即可