题意:。。。

析:随机判断就即可,每次把不正确的删除,经过几次后就基本剩不下了。

代码如下:

#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)的更多相关文章

  1. 【Codeforces 63C】Bulls and Cows

    [链接] 我是链接,点我呀:) [题意] 给你一个长度为4的数字序列(每个数字都在0~9之间,且不重复出现) 现在让你猜这个长度为4的序列是什么. 猜了之后对方会告诉有几个数字是位置和数字都正确的(猜 ...

  2. [LeetCode] Bulls and Cows 公母牛游戏

    You are playing the following Bulls and Cows game with your friend: You write a 4-digit secret numbe ...

  3. LeetCode 299 Bulls and Cows

    Problem: You are playing the following Bulls and Cows game with your friend: You write down a number ...

  4. [Leetcode] Bulls and Cows

    You are playing the following Bulls and Cows game with your friend: You write a 4-digit secret numbe ...

  5. Bulls and Cows

    You are playing the following Bulls and Cows game with your friend: You write down a number and ask ...

  6. 299. Bulls and Cows

    题目: You are playing the following Bulls and Cows game with your friend: You write down a number and ...

  7. Java [Leetcode 229]Bulls and Cows

    题目描述: You are playing the following Bulls and Cows game with your friend: You write down a number an ...

  8. [LeetCode299]Bulls and Cows

    题目: You are playing the following Bulls and Cows game with your friend: You write down a number and ...

  9. Bulls and Cows leetcode

    You are playing the following Bulls and Cows game with your friend: You write down a number and ask ...

随机推荐

  1. 谜题 UVA227

    这道题目还是不难的,但是要注意gcc里面gets已经不能用了,用gets_s还是可以的,尽管我并不知道有什么区别 #include<stdio.h>#include<stdlib.h ...

  2. uitabbarController tababr 上方横线隐藏

    在自定义的tabbarController里加上这一句就ok [[UITabBar appearance] setShadowImage:[UIImage new]]; [[UITabBar appe ...

  3. window.open实现模式窗口(只弹出一个window.open)

    父页面 <!DOCTYPE html> <html xmlns="http://www.w3.org/1999/xhtml"> <head> & ...

  4. sql 各种格式

    --以2013-12-10 12:56:55为例--convert(nvarchar(10),CreateDate,120)      =>      2013-12-10--DATEPART( ...

  5. EditText文本中用正则匹配是否包含数字,及判断文本只能是纯汉字或纯字母

    遇到判断EditText中文本,是否为制定格式 EditText et; Button btn; @Override protected void onCreate(Bundle savedInsta ...

  6. STL容器小结

     1.空间分配器 std::alloc用于容器中内存空间的分配和释放,以及分配内存的管理.construct().destroy()等全局函数用于为对象的构造和析构. 2.迭代器和trains 迭代器 ...

  7. javaWEB总结(10):HttpServlet成长史

    前言: 从Servlet,ServletConfig到GenericServlet再到Httpservlet的整个过程,相当于Httpservlet的成长史,我们不需要写那么臃肿的代码,开发难度由复杂 ...

  8. js--面向对象继承

    Object.create()方法可以传入一个原型对象,并创建一个基于该原型的新对象,但是新对象什么属性都没有. // 原型对象: var Student = { name: 'Robot', hei ...

  9. java中的字符编码方式

    1. 问题由来 面试的时候被问到了各种编码方式的区别,结果一脸懵逼,这个地方集中学习一下. 2. 几种字符编码的方式 1. ASCII码 我们知道,在计算机内部,所有的信息最终都表示为一个二进制的字符 ...

  10. MFC HTTP

    CInternetSession m_winet(NULL,,INTERNET_OPEN_TYPE_DIRECT,NULL,NULL,); CHttpConnection *pConnection; ...