题目描述:
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\n", 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);
}
原文地址:https://www.cnblogs.com/p-b-p-b/p/10279264.html
时间: 2024-10-10 14:18:42