链接: 原题链接
题目描述
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 " xx bulls yy cows". xx represents the number of digits in the experimental number that occupy the same positions as in the sought number. yy 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.
输入格式

输出格式
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.
题目大意
农夫约翰想要将N(1 <= N <= 100,000)奶牛和公牛排在一排,以便在年度展会上展示。
FJ观察到公牛最近非常好斗; 如果两条公牛队在一条线上太靠近,他们会争辩并开始战斗,破坏了演示。资源丰富,FJ计算出任何两只公牛必须在它们之间至少有K(0 <= K <N)奶牛才能避免战斗。
FJ希望你通过计算可以避免任何战斗的N头公牛和奶牛的可能序列来帮助他。FJ认为所有公牛都是一样的,所有的母牛都是一样的; 因此,如果两个序列在某个位置具有不同种类的牛,则它们只是不同的。
输入描述:
第1行:两个以空格分隔的整数:N和K.
输出描述:
第1行:一个整数,表示FJ可以创建这样一系列牛的方式。由于此数字可能非常大,因此输出模数为5,000,011的模数。
输入输出样例
输入
2
1263 1 2
8103 2 1
输出
Need more data
输入
1234 2 2
1256 0 2
输出
2134
输入
2
0123 1 1
4567 1 2
输出
Incorrect data
思路讲解
我们用Total记录有多少个数属于思考者所给出的数。
先看有答案的样例:
先看第一组数据,2公2母,Total是4,说明正确答案就是1 2 3 4这四个数的一种组合方式。再根据2公2母,公的个数就是位置对的个数,母就是位置错的的个数,那么就是说第一组数据有两个位置对,两个位置错。
再看第一二组数据:
0公2母,没有位置对的,有2个位置错的,那么我们先对比一下第一组和第二组数据,既然第二组有2个位置错的数据,那么肯定和第一组有2个公共数据,就是1和2。现在可以确定1和2的位置是错的,那么再看第一组数据,既然1和2的位置是错的,因为2公2母,则3和4的位置是对的,那么答案即为把1和2的位置交换一下:2134
再看第一组样例(need more data):
两组数据Total都是3,说明每组都有3个数字是正确答案中的数字。但是我们看这两组数据,公共

最低0.47元/天 解锁文章
122

被折叠的 条评论
为什么被折叠?



