欢迎来到起遇信息学
起遇信息学正处于上线筹建阶段,以下功能已全部开放免费体验: ✅ 完整题库浏览与代码提交评测(C / C++ / Python / Java 等) ✅ 入门到进阶的系列课程试读、作业与考试 ✅ AI 提示、AI 作业分析等智能助教功能 ✅ 赛事模拟与个人能力报告 ✅ 邮箱注册开放 ⏳ 付费课程订阅与微信/支付宝支付通道 ⏳ 手机号登录,微信扫码登录、微信公众号绑定 使用中如遇任何问题,欢迎通过页面底部 **"联系我们"** 与我们沟通。
CF2030C.A TRUE Battle
A TRUE Battle
Alice and Bob are playing a game. There is a list of booleans, each of which is either true or false, given as a binary string of length (where 1 represents true, and 0 represents false). Initially, there are no operators between the booleans.
Alice and Bob will take alternate turns placing and or or between the booleans, with Alice going first. Thus, the game will consist of turns since there are booleans. Alice aims for the final statement to evaluate to true, while Bob aims for it to evaluate to false. Given the list of boolean values, determine whether Alice will win if both players play optimally.
To evaluate the final expression, repeatedly perform the following steps until the statement consists of a single true or false:
- If the statement contains an
andoperator, choose any one and replace the subexpression surrounding it with its evaluation. - Otherwise, the statement contains an
oroperator. Choose any one and replace the subexpression surrounding theorwith its evaluation.
For example, the expression true or false and false is evaluated as true or (false and false) true or false true. It can be shown that the result of any compound statement is unique.
A binary string is a string that only consists of characters 0 and 1
Input
The first line contains () — the number of test cases.
The first line of each test case contains an integer () — the length of the string.
The second line contains a binary string of length , consisting of characters 0 and 1 — the list of boolean values.
It is guaranteed that the sum of over all test cases does not exceed .
Output
For each testcase, output "YES" (without quotes) if Alice wins, and "NO" (without quotes) otherwise.
You can output "YES" and "NO" in any case (for example, strings "yES", "yes" and "Yes" will be recognized as a positive response).
Note
In the first testcase, Alice can place and between the two booleans. The game ends as there are no other places to place operators, and Alice wins because true and true is true.
In the second testcase, Alice can place or between the middle true and the left false. Bob can place and between the middle true and the right false. The statement false or true and false is false.
Note that these examples may not be the best strategies for either Alice or Bob.
Samples
5
2
11
3
010
12
101111111100
10
0111111011
8
01000010
YES
NO
YES
YES
NO
在线编程 IDE
建议全屏模式获得最佳体验
| 进入全屏编程 | Alt+E |
| 递交评测 | Ctrl+Enter |
| 注释/取消注释 | Ctrl+/ |
| 缩放字体 | Ctrl+滚轮 |