CF2248A.You Delete, I Delete
入门
通过率:0%
时间限制:1.00s
内存限制:256MB
AC君温馨提醒
该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。
题目描述
Alice and Bob are given a binary string∗ s of length n. It contains at least one 0 and at least one 1.
They each perform exactly one operation in the following order:
- First, Alice chooses an occurrence of 0 in s and deletes it.
- Then, Bob chooses an occurrence of 1 in the resulting string and deletes it.
Alice wants the final string to be lexicographically† as large as possible, while Bob wants it to be lexicographically as small as possible. Determine the final string if both players act optimally.
∗A binary string is a string consisting only of the characters 0 and 1.
†For two distinct binary strings a and b of the same length, a is lexicographically smaller than b if, at the first position where they differ, a has the smaller digit.
Alice 和 Bob 得到一个长度为 n 的二进制字符串∗ s。该字符串中至少包含一个 0 和一个 1。
他们各自恰好执行一次操作,顺序如下:
- 首先,Alice 在 s 中选择一个 0 并将其删除;
- 然后,Bob 在删除后的字符串中选择一个 1 并将其删除。
Alice 希望最终字符串的字典序†尽可能大,而 Bob 希望其字典序尽可能小。若双方均采取最优策略,求最终字符串。
∗二进制字符串是指仅由字符 0 和 1 组成的字符串。
†对于两个长度相同且互不相同的二进制字符串 a 和 b,若在它们首次出现差异的位置上,a 的数字更小,则称 a 的字典序小于 b。
输入格式
Each test contains multiple test cases. The first line contains the number of test cases t (1≤t≤100). The description of the test cases follows.
The only line of each test case contains a binary string s of length n (3≤n≤100).
It is guaranteed that s contains at least one 0 and at least one 1.
每个测试包含多个测试用例。第一行包含测试用例的数量 t(1≤t≤100)。随后是测试用例的描述。
每个测试用例仅有一行,包含一个长度为 n 的二进制字符串 s(3≤n≤100)。
保证 s 中至少包含一个 0 和至少一个 1。
输出格式
For each test case, output the final string if both players act optimally.
对于每个测试用例,若双方玩家均采取最优策略,则输出最终的字符串。
输入输出样例
输入#1
4 101 11001 0010 0101010000010100100101
输出#1
1 101 00 01010000010100100101
说明/提示
In the first test case, Alice must delete the only 0. Bob may delete either occurrence of 1, so the resulting string is 1.
In the second test case, Alice may delete either occurrence of 0. Bob optimally deletes one of the first two occurrences of 1, so the resulting string is 101.
In the third test case, Alice may delete any occurrence of 0. Bob then deletes the only occurrence of 1, so the resulting string is 00.
在第一个测试用例中,Alice 必须删除唯一的 0。Bob 可以删除任意一个 1,因此最终字符串为 1。
在第二个测试用例中,Alice 可以删除任意一个 0。Bob 最优地删除前两个 1 中的任意一个,因此最终字符串为 101。
在第三个测试用例中,Alice 可以删除任意一个 0。随后 Bob 删除唯一的 1,因此最终字符串为 00。
输入解题思路,AI测评打分。不知道怎么写?