CF63C.Bulls and Cows
普及+/提高
通过率:0%
时间限制:2.00s
内存限制:256MB
AC君温馨提醒
该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。
题目描述
The "Bulls and Cows" game needs two people to play. The thinker thinks of a number and the guesser tries to guess it.
The thinker thinks of a four-digit number in the decimal system. All the digits in the number are different and the number may have a leading zero. It can't have more than one leading zero, because all it's digits should be different. The guesser tries to guess the number. He makes a series of guesses, trying experimental numbers and receives answers from the first person in the format "x bulls y cows". x represents the number of digits in the experimental number that occupy the same positions as in the sought number. y represents the number of digits of the experimental number that present in the sought number, but occupy different positions. Naturally, the experimental numbers, as well as the sought number, are represented by four-digit numbers where all digits are different and a leading zero can be present.
For example, let's suppose that the thinker thought of the number 0123. Then the guessers' experimental number 1263 will receive a reply "1 bull 2 cows" (3 occupies the same positions in both numbers and 1 and 2 are present in both numbers but they occupy different positions). Also, the answer to number 8103 will be "2 bulls 1 cow" (analogically, 1 and 3 occupy the same positions and 0 occupies a different one).
When the guesser is answered "4 bulls 0 cows", the game is over.
Now the guesser has already made several guesses and wants to know whether his next guess can possibly be the last one.
“公牛与母牛”(Bulls and Cows)游戏需要两人参与:一人构思一个数字,另一人尝试猜出该数字。
构思者在十进制下构思一个四位数。该数的所有数字互不相同,且允许以零开头(即首位可以是 0);但不能有多个前导零,因为所有数字必须互异。猜数者通过一系列猜测来尝试找出该数,每次给出一个实验性四位数,并从构思者处获得形如“x 头公牛 y 头母牛”的反馈。其中,x 表示实验数中位置与目标数完全相同的数字个数;y 表示实验数中在目标数中存在但位置不同的数字个数。显然,实验数和目标数均为满足“各位数字互异、允许前导零”的四位数。
例如,假设构思者想出的数字是 0123。若猜数者尝试 1263,则反馈为“1 头公牛 2 头母牛”(因为数字 3 在两个数中均位于第 4 位;而数字 1 和 2 均出现在两个数中,但在不同位置)。又如,对 8103 的反馈为“2 头公牛 1 头母牛”(同理:1 和 3 位置相同;0 存在于两个数中但位置不同)。
当猜数者得到“4 头公牛 0 头母牛”的反馈时,游戏结束。
现在,猜数者已进行若干次猜测,他希望知道:自己的下一次猜测是否有可能成为最终一猜(即是否可能直接得到“4 头公牛 0 头母牛”)。
输入格式
The first input line contains an integer n (1 ≤ n ≤ 10) which represents the number of already made guesses. Then follow n lines in the form of "a__i b__i c__i", where a__i is the i-th experimental number, b__i is the number of bulls, c__i is the number of cows (1 ≤ i ≤ n, 0 ≤ b__i, c__i, b__i + c__i ≤ 4). The experimental numbers are correct, i.e., each of them contains exactly four digits, in each of them all the four digits are different, and there can be a leading zero. All the experimental numbers are different. As the guesser hasn't guessed the number yet, the answer "4 bulls 0 cows" is not present.
第一行输入包含一个整数 n(1≤n≤10),表示已进行的猜测次数。随后是 n 行,每行格式为 "ai bi ci",其中 ai 是第 i 次试验所猜的数字,bi 是“公牛”(bulls)的数量,ci 是“母牛”(cows)的数量(1≤i≤n,0≤bi,ci,且 bi+ci≤4)。所有试验数字均合法,即每个数字恰好包含四位数字,每位数字互不相同,且允许前导零。所有试验数字互不相同。由于猜测者尚未猜中正确答案,因此输入中不会出现“4 公牛 0 母牛”的情况。
输出格式
If the input data is enough to determine the sought number, print the number with four digits on a single line. If it has less than four digits, add leading zero. If the data is not enough, print "Need more data" without the quotes. If the thinker happens to have made a mistake in his replies, print "Incorrect data" without the quotes.
如果输入数据足以确定所求的数,则在单独一行中输出该数,保留四位数字;若不足四位,则在前面补零。如果数据不足,则输出“Need more data”(不含引号)。如果猜数者在回答中恰好出现了错误,则输出“Incorrect data”(不含引号)。
输入输出样例
输入#1
2 1263 1 2 8103 2 1
输出#1
Need more data
输入#2
2 1234 2 2 1256 0 2
输出#2
2134
输入#3
2 0123 1 1 4567 1 2
输出#3
Incorrect data
输入解题思路,AI测评打分。不知道怎么写?