Blog of RuSun

\begin {array}{c} \mathfrak {One Problem Is Difficult} \\\\ \mathfrak {Because You Don't Know} \\\\ \mathfrak {Why It Is Diffucult} \end {array}

UOJ454. 【UER 8】打雪仗

UOJ454. 【UER 8】打雪仗

对于每三个数,bob 告诉 alice 前两个数是否需要,alice 告诉 bob 需要的数并直接告诉第 3 个数,这样 bob 的次数为 $2n \times \frac 2 3 = \frac 4 3 n$ ,alice 的次数为 $n + n \times \frac 1 3 = \frac 4 3 n$ ,这样都满足条件了。

千万不要用 scanf("%1d", &a) ,被卡了一个小时不知道哪里错了,大概是 scanf 会一直等,然后 T 飞。

查看代码
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
//alice.cpp
#include <cstdio>
#include <cstdlib>
#include <iostream>
using namespace std;
const int N = 1e3 + 10;
int n, m, s[N << 1];
int main ()
{
FILE *in = fopen("alice.in", "r");
fscanf(in, "%d%d", &n ,&m);
for (int i = 1; i <= n << 1; ++i) fscanf(in, "%1d", &s[i]);
for (int i = 1; i <= n << 1; i += 3)
{
if (getchar() == '1') printf("%d", s[i]);
if (getchar() == '1') printf("%d", s[i + 1]);
printf("%d", s[i + 2]);
fflush(stdout);
}
return 0;
}
//bob.cpp
#include <cstdio>
#include <vector>
using namespace std;
const int N = 1e3 + 10;
vector <bool> ans;
int n, m;
bool p[N << 1];
int main ()
{
FILE *in = fopen("bob.in", "r"), *out = fopen("bob.out", "w");
fscanf(in, "%d%d", &n, &m);
for (int i = 1, t; i <= n; ++i)
fscanf(in, "%d", &t), p[t] = true;
for (int i = 1; i <= n << 1; i += 3)
{
printf("%d%d", p[i], p[i + 1]);
fflush(stdout);
if (p[i]) ans.push_back(getchar() - '0');
if (p[i + 1]) ans.push_back(getchar() - '0');
bool a = getchar() - '0'; if (p[i + 2]) ans.push_back(a);
}
for (bool i : ans) fprintf(out, "%d", i);
return 0;
}