CF753B.Interactive Bulls and Cows (Easy)
普及/提高-
通过率:0%
时间限制:2.00s
内存限制:256MB
AC君温馨提醒
该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。
题目描述
This problem is a little bit unusual. Here you are to implement an interaction with a testing system. That means that you can make queries and get responses in the online mode. Please be sure to use the stream flushing operation after each query's output in order not to leave part of your output in some buffer. For example, in C++ you've got to use the fflush(stdout) function, in Java — call System.out.flush(), and in Pascal — flush(output).
Bulls and Cows (also known as Cows and Bulls or Pigs and Bulls or Bulls and Cleots) is an old code-breaking paper and pencil game for two players, predating the similar commercially marketed board game Mastermind.
On a sheet of paper, the first player thinks a secret string. This string consists only of digits and has the length 4. The digits in the string must be all different, no two or more equal digits are allowed.
Then the second player tries to guess his opponent's string. For every guess the first player gives the number of matches. If the matching digits are on their right positions, they are "bulls", if on different positions, they are "cows". Thus a response is a pair of numbers — the number of "bulls" and the number of "cows". A try can contain equal digits.
More formally, let's the secret string is s and the second player are trying to guess it with a string x. The number of "bulls" is a number of such positions i (1 ≤ i ≤ 4) where s[i] = x[i]. The number of "cows" is a number of such digits c that s contains c in the position i (i.e. s[i] = c), x contains c, but x[i] ≠ c.
For example, the secret string is "0427", the opponent's try is "0724", then the answer is 2 bulls and 2 cows (the bulls are "0" and "2", the cows are "4" and "7"). If the secret string is "0123", the opponent's try is "0330", then the answer is 1 bull and 1 cow.
In this problem you are to guess the string s that the system has chosen. You only know that the chosen string consists of 4 distinct digits.
You can make queries to the testing system, each query is the output of a single 4-digit string. The answer to the query is the number of bulls and number of cows. If the system's response equals "4 0", that means the interaction with your problem is over and the program must terminate. That is possible for two reasons — the program either guessed the number x or made an invalid action (for example, printed letters instead of digits).
Your program is allowed to do at most 50 queries.
You can hack solutions of other participants providing a 4-digit string containing distinct digits — the secret string.
本题略有不同:你需要实现与评测系统的交互。这意味着你可以发起查询,并在线获得响应。请务必在每次输出查询后执行流刷新操作,以免部分输出滞留在缓冲区中。例如,在 C++ 中需调用 fflush(stdout) 函数;在 Java 中需调用 System.out.flush();在 Pascal 中需调用 flush(output)。
“公牛与母牛”(Bulls and Cows,又称“母牛与公牛”、“猪与公牛”或“公牛与克里奥茨”)是一款古老的纸笔式密码破译游戏,由两名玩家参与,其历史早于后来商业化发行的棋盘游戏“Mastermind”。
在一张纸上,第一名玩家构思一个秘密字符串。该字符串仅由数字组成,长度为 4,且其中所有数字互不相同(不允许出现两个或更多相同的数字)。
随后,第二名玩家尝试猜测对手的字符串。对于每一次猜测,第一名玩家会给出匹配数量的反馈:若某数字在猜测串中出现的位置与其在秘密串中的位置完全一致,则该数字称为“公牛”(bull);若某数字在猜测串中出现,但位置与秘密串中不同,则该数字称为“母牛”(cow)。因此,每次反馈是一对整数——“公牛”的数量与“母牛”的数量。注意:猜测串中允许包含重复数字。
更形式化地定义如下:设秘密字符串为 s,第二名玩家的猜测串为 x。则“公牛”的数量等于满足 s[i]=x[i] 的位置 i 的个数(其中 1≤i≤4);而“母牛”的数量等于满足如下条件的数字 c 的个数:s 在某个位置 i 上含有 c(即 s[i]=c),x 中也包含 c,但 x[i]=c。
举例说明:若秘密字符串为 "0427",对手猜测为 "0724",则反馈为 2 头公牛和 2 头母牛(公牛为 "0" 和 "2",母牛为 "4" 和 "7");若秘密字符串为 "0123",对手猜测为 "0330",则反馈为 1 头公牛和 1 头母牛。
在本题中,你需要猜出系统所选定的秘密字符串 s。你唯一已知的信息是:该字符串由 4 个互不相同的数字构成。
你可以向评测系统发起查询,每次查询即输出一个长度为 4 的数字字符串。系统将返回两个整数:公牛数与母牛数。若系统返回 "4 0",则表示本次交互结束,你的程序必须立即终止。出现该情况可能有两个原因:一是你的程序已成功猜中字符串 x;二是你的程序执行了非法操作(例如输出了字母而非数字)。
你的程序最多允许发起 50 次查询。
你可以通过提供一个由 4 个互不相同数字组成的字符串(即秘密字符串)来对其他参赛者的解法进行 hack。
输入格式
To read answers to the queries, the program must use the standard input.
The program will receive pairs of non-negative integers in the input, one pair per line. The first number in a pair is a number of bulls and the second one is a number of cows of the string s and the string x__i printed by your program. If the system response equals "4 0", then your solution should terminate.
The testing system will let your program read the i-th pair of integers from the input only after your program displays the corresponding system query in the output: prints value x__i in a single line and executes operation flush.
要读取查询的答案,程序必须使用标准输入。
程序将从输入中接收若干对非负整数,每行一对。每对中的第一个数表示字符串 s 与你的程序所输出的字符串 x__i 之间的“公牛”(bulls)数目,第二个数表示“母牛”(cows)数目。若系统响应为 "4 0",则你的程序应终止运行。
评测系统仅在你的程序向输出中打印了对应的系统查询(即在单行中输出值 x__i 并执行 flush 操作)之后,才允许你的程序从输入中读取第 i 对整数。
输出格式
The program must use the standard output to print queries.
Your program must output requests — 4-digit strings _x_1, _x_2, ..., one per line. After the output of each line the program must execute flush operation. The program should read the answer to the query from the standard input.
Your program is allowed to do at most 50 queries.
程序必须使用标准输出打印查询。
你的程序必须输出请求——即若干个四位字符串 x1,x2,…,每个字符串独占一行。每输出一行后,程序必须执行刷新(flush)操作。程序应从标准输入读取该查询的响应。
你的程序最多允许进行 50 次查询。
输入输出样例
输入#1
0 1 2 0 1 1 0 4 2 1 4 0
输出#1
8000 0179 3159 3210 0112 0123
说明/提示
The secret string s in the example is "0123".
示例中的秘密字符串 s 是 "0123"。
输入解题思路,AI测评打分。不知道怎么写?