AOJ 2084 Hit and Blow
来源:互联网 发布:淘宝女装店铺介绍范文 编辑:程序博客网 时间:2024/06/07 21:15
非常有趣的模拟题, 题意是曾经很火的小游戏: 猜数字
首先出题人决定了一个秘密可带前导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>#include <cmath>#include <vector>#include <queue>#include <stack>#include <map>#include <set>#include <algorithm>#include <climits>#define MAXN 205#define N 105#define inf 1.0e20#define eps 1.0e-10#define MOD 1000000007#define For(i,m,n) for(int i=(m);i<(n);i++)#define vecfor(iter,a) for(vector<int>::iterator iter=a.begin();iter!=a.end();iter++)#define rep(i,m,n) for(int i=(m);i<=(n);i++)#define LL long longusing namespace std;vector<int> ans, all, temp;int hit, blow, att;int h(int a, int b) //计算hit数{ int x=0; For(i,0,4) x+=(a%10==b%10),a/=10,b/=10; return x;}int b(int a, int b) //计算blow数{ int x=0, aa=a, bb; For(i,0,4){ bb=b; For(j,0,4){ if(i!=j&&aa%10==bb%10) x++; bb/=10; } aa/=10; } return x;}bool differ(int x) //各位数字不同{ bool vis[10]={false}; For(i,0,4){ if(vis[x%10]) return false; else vis[x%10]=true; x/=10; } return true;}int main(){ int T, n; rep(i,123,9876) if(differ(i)) all.push_back(i); //全集合 while(scanf("%d",&n),n){ ans=all; rep(i,1,n){ scanf("%d%d%d",&att,&hit,&blow); temp.clear(); vecfor(iter,ans) if(h(*iter,att)==hit&&b(*iter,att)==blow) temp.push_back(*iter); ans=temp; //每次猜测都将缩减答案集合 //vecfor(iter,ans) printf("%6d",*iter); } if(ans.empty()) puts("????"); else if(ans.size()==1) printf("%04d\n",ans[0]); else if(ans.size()<=24){ //答案数超过24即表明不能确定这个四位数的各个数字, 明显不能解出答案 bool hb[5][5]; vecfor(iter1,all){ memset(hb,false,sizeof hb); vecfor(iter2,ans){ int th=h(*iter1,*iter2), tb=b(*iter1,*iter2); if(hb[th][tb]) goto next; else hb[th][tb]=true; } printf("%04d\n",*iter1); goto end; next:; } puts("????"); end:; } else puts("????"); } return 0;}
0 0
- AOJ 2084 Hit and Blow
- Hit-and-Miss Transform
- Hit Testing Lines and Curves
- 肇事逃逸 hit-and-run
- HIT-Red and Black DFS
- and hit a jackpot w
- AOJ 0005 GCD and LCM
- we've selected points 2 minutes above and blow t=3 minutes
- Hit rate and False alarm rate
- AOJ
- Aoj
- blow your socks up
- 关于Cache hit and miss rate --grassbell的博客
- AOJ 0005 GCD and LCM (最大公约数_裸题)
- Blow one's own horn 自吹自擂
- gem5: the trace of cache set and cache line write hit counters
- OllyDbg完全教程 单步执行与自动执行[Step-by-step execution and animation] Hit跟踪[Hit trace]
- OllyDbg完全教程 单步执行与自动执行[Step-by-step execution and animation] Hit跟踪[Hit trace]
- 一些常用的正则匹配规则
- android中发送短信的三种方法
- Shell排序
- 完美软件开发:方法与逻辑
- Codeforces 431 D. Random Task
- AOJ 2084 Hit and Blow
- 当随机不够随机:一个在线扑克游戏的教训
- 创建JavaScript自定义对象的方式
- 现场故障小结——非当前日志组损坏情况
- andorid 调用自己写的WebService
- ArrayList源码阅读笔记
- 弃用了struts,用spring mvc框架做了几个项目
- 在Linux下卸载Oracle 11g
- fedora-vim-conf-lite