2019雅礼集训 D10T2 硬币翻转 [交互题]

Posted p-b-p-b

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了2019雅礼集训 D10T2 硬币翻转 [交互题]相关的知识,希望对你有一定的参考价值。

题目描述:

技术分享图片

技术分享图片

技术分享图片

coin.h:

#include<string>
void guess();
int ask(std::string coin);

grader.cpp:

#include "coin.h"
#include <iostream>
#include <assert.h>

using namespace std;

namespace U {
    using u64 = unsigned long long;
    using i64 = long long;
    
    static struct random_t {
        u64 s0, s1;
        random_t(){
            s0 = 0x0123456789abcdef;
            s1 = 0xfedcba9876543210;
        }
        random_t(u64 s0, u64 s1):s0(s0), s1(s1){}
        u64 get(){
            std::swap(s0, s1);
            s1 ^= s1 << 23, s1 ^= (s1 >> 17) ^ s0 ^ (s0 >> 26);
            return s0 + s1;
        }
        int randint(int L, int R){
            return get() % (R - L + 1) + L;
        }
    } rnd;
    
    static int Test;
    static string coin;
    static int queries;
    
    struct info{};
    
    int ask(string guess){
        ++queries;
        assert(guess.size() == 100);
        int ret = 0, x;
        for (x = 0; x < 100; ++x) {
            assert(guess[x] == ‘0‘ || guess[x] == ‘1‘);
            if (guess[x] == coin[x]) {
                ++ret;
            }
        }
        if (ret == 100) {
            throw info();
        }
        x = rnd.randint(0, 99);
        if (guess[x] == coin[x]) {
            coin[x] ^= 1;
        }
        return ret;
    }
    
    static int test;
    static string loc[105];
    
    void main(){
        cin >> rnd.s0 >> rnd.s1;
        cin >> Test;
        for (test = 1; test <= Test; ++test) {
            cin >> loc[test];
        }
        fclose(stdin);
        double answer = 100;
        for (test = 1; test <= Test; ++test) {
            double point = 0;
            coin = loc[test];
            assert(coin.size() == 100);
            try {
                guess();
            } catch (info suc) {
                if (queries <= 200) point = 100;
                else if (queries <= 600) point = 120 - 0.15 * queries;
                else point = 36 - 0.01 * queries;
                if (point < 0) point = 0;
                queries = 0;
            }
            answer = min(answer, point);
            if (answer == 0) break;
        }
        puts("auhrouahrbahdfnaldkssafbaufnianfiamofmaf");
        printf("%.2lf
", answer);
    }
}

int ask(string guess){return U::ask(guess);}
int main(){U::main();}

简单交互题,不做解释,直接放题解

技术分享图片

技术分享图片

标程:

#include "coin.h"
#include <string>

void guess(){
    srand(23333);
    std::string s = "";
    int cnt, ncnt, x;
    for (x = 0; x < 100; ++x) {
        s += (rand() & 1) + ‘0‘;
    }
    cnt = ask(s);
    for (x = 0; x < 100; ++x) {
        while (true) {
            s[x] ^= 1;
            ncnt = ask(s);
            if (cnt > ncnt) break;
            cnt = ncnt;
        }
        cnt = ncnt;
    }
    for (x = 0; x < 100; ++x) {
        s[x] ^= 1;
    }
    ask(s);
}

以上是关于2019雅礼集训 D10T2 硬币翻转 [交互题]的主要内容,如果未能解决你的问题,请参考以下文章

2019雅礼集训 D7T1 inverse [概率/期望,DP]

2019雅礼集训 D4T1 w [费用流]

2019雅礼集训 D7T3 convex [咕咕咕]

LOJ #6035.「雅礼集训 2017 Day4」洗衣服 贪心

2019雅礼集训 D8T1 union [咕咕咕]

[2018雅礼集训1-16]方阵