当前位置: 代码迷 >> 综合 >> AOJ 2084 Hit and Blow
  详细解决方案

AOJ 2084 Hit and Blow

热度:29   发布时间:2024-01-12 05:22:14.0

非常有趣的模拟题, 题意是曾经很火的小游戏: 猜数字

首先出题人决定了一个秘密可带前导0的四位数, 然后每轮挑战者也提出一个可有前导0的四位数字, 就会得到一个结果 X hit Y blow

hit 表示数字对位置也对, blow表示数字对但位置不对

比如秘密数字为1579 挑战者提出2507 就会得到1 hit 1 blow的结果

现在给定一个猜测数次的结果, 询问挑战者能否依靠逻辑在下两次尝试中猜出正确答案

如果不能猜的正确答案, 输出????, 否则 如果只有唯一解, 输出答案, 如果不是唯一解, 输出最小的critical number, 关键数的定义如下:

critical numbers mean those such that, after being given the number of hits and blows for them on the next attempt, the codebreaker can determine the secret number uniquely.(意即为解出答案下一次需要尝试的数)

注意题意要求每位数字都不同

暴力0123至9876即可

具体解法可见代码>>>


/*author: birdstorm*/
#include <iostream>
#include <cstdio>
#include <cstring>
#include <cctype>
#include <cstdlib>
#