题意:。。。

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

代码如下:

#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. UEFI主板GPT方式安装CentOS6.4

    1. 设置BIOS:禁用CSM,禁用安全启动:      或不用禁用CSM,但以EFI方式安装系统: 2. 使用Diskgen或类似工具把硬盘格式为GPT格式(可以建立多于4个的主分区了): 3. 官 ...

  2. web.confgi转换,web发布时发布配置(debug/release)生成不同的配置文件

    在web.config下有两个config文件,分比为:web.debug.config和web.replease.config文件,打开之后可以看到demo,根据demo修改后即可在发布时根据选择的 ...

  3. iOS 10 / Swift 3.0 / XCode 8 总结

    1,iOS10 新增的privacy settings iOS10添加了新的权限控制范围 如果你尝试访问这些隐私数据时得到如下错误: > This app has crashed because ...

  4. js 循环迭代定时器的执行次数和执行顺序??主要是因为js是单线程

    当定时器运行时即使每个迭代中执行的是setTimeout(.., 0),所有的回调函数依然是在循环结束后才会被执行 for语句开始赋值i=1;settimeout语句1000毫秒后把timer函数加入 ...

  5. MUI判断网络连接以及监听网络变化JS

    来源:netChange问题:怎么判断网络状态 MUI用于获取当前设备的网络类型 function plusReady(){ var types = {}; types[plus.networkinf ...

  6. ES 集群调整、升级 最佳实践

    日常应用中我们会经常对es 集群做一些参数调整或者升级版本,但是每次关闭节点再打开 其中的数据同步的痛苦估计有很多人领悟过(有可能出现IO或者网络拥堵导致恶性循环)官网有套方案可以尝试一下: 1.关掉 ...

  7. B/S和C/S的区别。

    现在软件开发的整体架构主要分为B/S架构与C/S架构 一,C/S——Client/Service:客户机/服务器模式: C/S (Client/Server)结构,即大家熟知的客户机和服务器结构.它是 ...

  8. MongoDB聚合管道(Aggregation Pipeline)

    参考聚合管道简介 聚合管道 聚合管道是基于数据处理管道模型的数据聚合框架.文档进入一个拥有多阶段(multi-stage)的管道,并被管道转换成一个聚合结果.最基本的管道阶段提供了跟查询操作类似的过滤 ...

  9. 6.Hibernate单向的多对一 关联映射

    1.创建如下项目结构 2.在项目的src下创建hibernate.cfg.xml主配置文件 <?xml version="1.0" encoding="UTF-8& ...

  10. Java常用集合类(1)

    一.HashMap 参考文章: http://yikun.github.io/2015/04/01/Java-HashMap%E5%B7%A5%E4%BD%9C%E5%8E%9F%E7%90%86%E ...