CodeForces 753C Interactive Bulls and Cows (Hard)
题意:。。。
析:随机判断就即可,每次把不正确的删除,经过几次后就基本剩不下了。
代码如下:
#pragma comment(linker, "/STACK:1024000000,1024000000")
#include <cstdio>
#include <string>
#include <cstdlib>
#include <cmath>
#include <iostream>
#include <cstring>
#include <set>
#include <queue>
#include <algorithm>
#include <vector>
#include <map>
#include <cctype>
#include <cmath>
#include <stack>
#include <sstream>
#include <unordered_map>
#include <unordered_set>
#define debug() puts("++++");
#define freopenr freopen("in.txt", "r", stdin)
#define freopenw freopen("out.txt", "w", stdout)
using namespace std; typedef long long LL;
typedef unsigned long long ULL;
typedef pair<int, int> P;
const int INF = 0x3f3f3f3f;
const LL LNF = 1LL << 60;
const double inf = 0x3f3f3f3f3f3f;
const double PI = acos(-1.0);
const double eps = 1e-8;
const int maxn = 100 + 5;
const int mod = 2000;
const int dr[] = {-1, 1, 0, 0};
const int dc[] = {0, 0, 1, -1};
const char *de[] = {"0000", "0001", "0010", "0011", "0100", "0101", "0110", "0111", "1000", "1001", "1010", "1011", "1100", "1101", "1110", "1111"};
int n, m;
const int mon[] = {0, 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};
const int monn[] = {0, 31, 29, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};
inline bool is_in(int r, int c){
return r >= 0 && r < n && c >= 0 && c < m;
}
bool use[15]; P query(const string &s){
cout << s << endl;
int a, b;
cin >> a >> b;
return P(a, b);
} void dfs(int d, string s, vector<string> &v){
if(4 == d){
v.push_back(s);
return ;
}
for(int i = 0; i < 10; ++i) if(!use[i]){
use[i] = true;
dfs(d+1, s + (char)('0' + i), v);
use[i] = false;
}
} bool judge(const string &s1, const string &s2, P &p){
int cnt1 = 0;
for(int i = 0; i < 4; ++i)
if(s1[i] == s2[i]) ++cnt1;
int cnt2 = 0;
for(int i = 0; i < 4; ++i)
for(int j = 0; j < 4; ++j)
if(s2[i] == s1[j]){ ++cnt2; break; }
return cnt1 == p.first && (cnt2 - cnt1 == p.second);
} vector<string> solve(P &p, vector<string> &v){
vector<string> tmp;
for(int i = 1; i < v.size(); ++i)
if(judge(v[0], v[i], p)) tmp.push_back(v[i]);
return tmp;
} #include <ctime>
int main(){
fflush(stdout);
srand(2333333);
vector<string> v;
memset(use, 0, sizeof use);
dfs(0, "", v);
while(true){
random_shuffle(v.begin(), v.end());
P tmp = query(v[0]);
if(tmp.first == 4) break;
v = solve(tmp, v);
}
return 0;
}
CodeForces 753C Interactive Bulls and Cows (Hard)的更多相关文章
- 【Codeforces 63C】Bulls and Cows
[链接] 我是链接,点我呀:) [题意] 给你一个长度为4的数字序列(每个数字都在0~9之间,且不重复出现) 现在让你猜这个长度为4的序列是什么. 猜了之后对方会告诉有几个数字是位置和数字都正确的(猜 ...
- [LeetCode] Bulls and Cows 公母牛游戏
You are playing the following Bulls and Cows game with your friend: You write a 4-digit secret numbe ...
- LeetCode 299 Bulls and Cows
Problem: You are playing the following Bulls and Cows game with your friend: You write down a number ...
- [Leetcode] Bulls and Cows
You are playing the following Bulls and Cows game with your friend: You write a 4-digit secret numbe ...
- Bulls and Cows
You are playing the following Bulls and Cows game with your friend: You write down a number and ask ...
- 299. Bulls and Cows
题目: You are playing the following Bulls and Cows game with your friend: You write down a number and ...
- Java [Leetcode 229]Bulls and Cows
题目描述: You are playing the following Bulls and Cows game with your friend: You write down a number an ...
- [LeetCode299]Bulls and Cows
题目: You are playing the following Bulls and Cows game with your friend: You write down a number and ...
- Bulls and Cows leetcode
You are playing the following Bulls and Cows game with your friend: You write down a number and ask ...
随机推荐
- 小例子解释wait与notify的区别
系统慢可能有很多种原因,硬件资源不足,语句不优化,结构设计不合理,缺少必要的运维方式.所有的这些问题都可以在阻塞与等待中看出端倪,发现并解决问题. 首先是下载开发工具,磨刀不误砍材工.点此下载 这是一 ...
- mac上搭建python+selenium2的环境
1.mac默认已安装有python和easy_install 2.进入终端,使用root的权限,然后输入,回车后需要root的密码,即可安装成功,成功结果如下所示 sudo easy_install ...
- C#调用托管C++类(DLL)
毕设是做一个网络摄像头的相关应用.界面用WPF,图像处理部分是OpenCV.没用EmguCV的原因是国内EmguCV的资料相对比较少,EmguCV虽然提供了Winform的控件,在做UI上有一定优势, ...
- 二十、oracle pl/sql基础
一.pl/sql developer开发工具pl/sql developer是用于开发pl/sql块的集成开发环境(ide),它是一个独立的产品,而不是oracle的一个附带品. 二.pl/sql介绍 ...
- PNPOLY - Point Inclusion in Polygon Test
https://www.ecse.rpi.edu/Homepages/wrf/Research/Short_Notes/pnpoly.html The C Code Here is the code, ...
- 外部系统集成BIEE
1.外部系统集成BIEE 隐藏工具栏和仪表盘右上角的菜单 2.BIEE 11g 嵌入Iframe InIFrameRenderingMode有三种取值,分别是prohibit.sameDomainOn ...
- Shell出现cd命令无法识别
出现cd 等命令无法识别的原因可能是: 当前文件实在windows环境下编辑的其换行结尾是 \r\n 和linux环境的 \n 不一致导致错误, 最好在linux系统上通过 VI 命令新建文件,然后通 ...
- 湖南多校对抗赛(2015.05.03)Problem B: War
并查集.从后往前加边. #include<stdio.h> #include<string.h> #include<math.h> #include<algo ...
- ios常见问题 经验之谈
1.既然有问题我们该怎样解决 ? 首先大部分人都会去百度搜索来解决问题, 谁都不例外, 可是百度这东西会有很多误解, 甚至误人子弟, 同时解决问题的效率也不是很高, 如果是技术问题可以去: Googl ...
- POJ 2485 Highway(Prim+邻接矩阵)
( ̄▽ ̄)" //求最短总路径中的最大边长,Prim还需要一个Max变量 #include<iostream> #include<cstdio> #include&l ...