题解:CF1510I Is It Rated?
Federico2903 · · 题解
做别的题的时候无意间发现的一道看起来挺有意思的交互题。
第一眼过去有一个假贪心,每次按照每个人的正确率对其选择加权然后求和,选择更大的那一边。
但是过不去一点。
看了官方题解过后发现正解是这样的:
首先每个人有一个可信程度
随后使用可信程度来加权选项然后求和,设选
随后检查每个人的答案,如果这个人这一轮答错了,他的
实际上,如果不随机化,官方题解里说这种情况的错误数量在每个人正确与错误数量之比达到
详细的证明可以看官方题解里面的 Wikipedia 的链接。
AC 代码
#include <bits/stdc++.h>
#define rep(i, a, b) for(int i = (a), i##end = (b); i <= i##end; i++)
#define _rep(i, a, b) for(int i = (a), i##end = (b); i >= i##end; i--)
#define ec first
#define fb second
#define dl make_pair
#define dk(...) make_tuple(__VA_ARGS__)
using namespace std;
typedef long long ll;
typedef pair <int, int> pii;
int read() {
int x = 0, f = 1; char c = getchar();
while (!isdigit(c)) {
if (c == '-') f = -1;
c = getchar();
}
while (isdigit(c)) {
x = (x << 3) + (x << 1) + (c ^ 48);
c = getchar();
}
return x * f;
}
template <typename _Tp>
void print(_Tp x) {
if (x < 0) x = (~x + 1), putchar('-');
if (x > 9) print(x / 10);
putchar(x % 10 + '0');
}
int n, m;
double sc[2005];
const double delta = 0.8;
mt19937 rnd(time(0));
signed main() {
cin >> n >> m;
rep (i, 1, n) sc[i] = 1;
rep (i, 1, m) {
string str;
cin >> str;
str = ' ' + str;
double zsum = 0;
double tsum = 0;
rep (j, 1, n) {
zsum += str[j] == '0' ? sc[j] : 0;
tsum += sc[j];
}
uniform_real_distribution <double> r(0, tsum);
double val = r(rnd);
if (val <= zsum) cout << 0 << endl;
else cout << 1 << endl;
char answer = read() + 48;
rep (j, 1, n) {
if (str[j] != answer) sc[j] *= delta;
}
}
return 0;
}