首页 > 其他 > 详细

CodeForces 753C Interactive Bulls and Cows (Hard)

时间:2017-01-14 23:03:08      阅读:392      评论:0      收藏:0      [点我收藏+]

题意:。。。

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

代码如下:

#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)

原文:http://www.cnblogs.com/dwtfukgv/p/6286295.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!