CF690A3.Collective Mindsets (hard)
普及/提高-
通过率:0%
时间限制:4.00s
内存限制:256MB
AC君温馨提醒
该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。
题目描述
Heidi got one brain, thumbs up! But the evening isn't over yet and one more challenge awaits our dauntless agent: after dinner, at precisely midnight, the N attendees love to play a very risky game...
Every zombie gets a number n__i (1 ≤ n__i ≤ N) written on his forehead. Although no zombie can see his own number, he can see the numbers written on the foreheads of all N - 1 fellows. Note that not all numbers have to be unique (they can even all be the same). From this point on, no more communication between zombies is allowed. Observation is the only key to success. When the cuckoo clock strikes midnight, all attendees have to simultaneously guess the number on their own forehead. If at least one of them guesses his number correctly, all zombies survive and go home happily. On the other hand, if not a single attendee manages to guess his number correctly, all of them are doomed to die!
Zombies aren't very bright creatures though, and Heidi has to act fast if she does not want to jeopardize her life. She has one single option: by performing some quick surgery on the brain she managed to get from the chest, she has the ability to remotely reprogram the decision-making strategy of all attendees for their upcoming midnight game! Can you suggest a sound strategy to Heidi which, given the rules of the game, ensures that at least one attendee will guess his own number correctly, for any possible sequence of numbers on the foreheads?
Given a zombie's rank R and the N - 1 numbers n__i on the other attendees' foreheads, your program will have to return the number that the zombie of rank R shall guess. Those answers define your strategy, and we will check if it is flawless or not.
海蒂获得了一个大脑,赞一个!但夜晚尚未结束,我们的无畏特工还将面临最后一项挑战:晚餐之后,恰好午夜时分,这 N 位与会者热衷于玩一场极其危险的游戏……
每位僵尸额头上都写有一个数字 n__i(1 ≤ n__i ≤ N)。尽管每位僵尸都无法看到自己额头上的数字,但他能看清其余 N − 1 位同伴额头上的全部数字。注意:这些数字不必互不相同(甚至可以全部相同)。自此之后,僵尸之间严禁任何形式的交流。唯有观察,才是制胜关键。当布谷鸟钟敲响午夜十二点时,所有与会者必须同时猜出自己额头上的数字。若其中至少一人猜对了自己额头上的数字,则全体僵尸幸存,并高高兴兴回家;反之,若无人猜对自己额头上的数字,则全体 doomed(注定死亡)!
然而,僵尸毕竟不是聪慧的生物,而海蒂若想保全性命,就必须迅速行动。她仅有一个机会:借助她刚从胸腔中取出的那颗大脑,通过一次快速手术,她有能力远程重编程所有与会者在即将到来的午夜游戏中的决策策略!你能为海蒂提出一个稳妥可靠的策略吗?该策略须严格遵循游戏规则,确保:对于额头数字序列的任意可能取值,都至少有一人能正确猜出自己额头上的数字。
给定某位僵尸的序号 R,以及其余 N − 1 位与会者额头上的数字 n__i,你的程序需返回这位序号为 R 的僵尸应当猜测的数字。这些输出共同定义了你所设计的策略,我们将据此检验该策略是否完美无瑕。
输入格式
The first line of input contains a single integer T (1 ≤ T ≤ 50000): the number of scenarios for which you have to make a guess.
The T scenarios follow, described on two lines each:
- The first line holds two integers, N (2 ≤ N ≤ 6), the number of attendees, and R (1 ≤ R ≤ N), the rank of the zombie who has to make the guess.
- The second line lists N - 1 integers: the numbers on the foreheads of all other attendees, listed in increasing order of the attendees' rank. (Every zombie knows the rank of every other zombie.)
输入的第一行包含一个整数 T(1≤T≤50000):你需要进行猜测的场景数量。
接下来是 T 个场景,每个场景由两行描述:
- 第一行包含两个整数:N(2≤N≤6),表示与会者人数;以及 R(1≤R≤N),表示需要进行猜测的僵尸的排名。
- 第二行包含 N−1 个整数:其余所有与会者额头上的数字,按与会者排名升序列出。(每个僵尸都知道其他所有僵尸的排名。)
输出格式
For every scenario, output a single integer: the number that the zombie of rank R shall guess, based on the numbers n__i on his N - 1 fellows' foreheads.
对于每种情形,输出一个整数:僵尸根据其 N−1 个同伴额头上的数字 ni 所应猜测的数字(该僵尸的排名为 R)。
输入输出样例
输入#1
4 2 1 1 2 2 1 2 1 2 2 2 2
输出#1
1 2 2 1
输入#2
2 5 2 2 2 2 2 6 4 3 2 6 1 2
输出#2
5 2
说明/提示
For instance, if there were N = 2 two attendees, a successful strategy could be:
- The zombie of rank 1 always guesses the number he sees on the forehead of the zombie of rank 2.
- The zombie of rank 2 always guesses the opposite of the number he sees on the forehead of the zombie of rank 1.
例如,假设有 N=2 位参与者,则一种成功的策略可以是:
- 排名为 1 的僵尸总是猜测他所看到的、排名为 2 的僵尸额头上显示的数字;
- 排名为 2 的僵尸总是猜测与他所看到的、排名为 1 的僵尸额头上显示的数字相反的数字。
输入解题思路,AI测评打分。不知道怎么写?