当前位置:网站首页>【UOJ 454】打雪仗(通信题)(分块)
【UOJ 454】打雪仗(通信题)(分块)
2022-08-11 09:38:00 【SSL_TJH】
打雪仗
题目链接:UOJ 454
题目大意
通信题。
两个人 A 有一个 2n 的 01 的字符串,B 有 n 个要知道的位置。
两个人可以传 01 给对方,然后最多的人不能传超过 4/3n(会多一点)个字符。
要你操作,使得 B 知道每个位置是 0 是 1。
思路
发现大概是 2 n 2n 2n 的 2 3 \frac{2}{3} 32,考虑能不能均摊一下了两个人的消费。
(因为你最暴力可以理解为一个人不说话,第二个把所有人都丢给他,考虑让那个不说话也说说话提供信息)
然后不难想到各种 50 分的写法。
然后再看看这个 2 3 \frac{2}{3} 32,我们考虑分块。
给的那个通过一个一开始的信息得到最多的是哪个,然后整块给,然后剩下的就看对面的 01 串是 1 1 1 就表示要,就给。
那这样剩下两个块至多给 2 3 n \frac{2}{3}n 32n 加上你 1 3 2 n \frac{1}{3}2n 312n 刚好 2 3 2 n \frac{2}{3}2n 322n。
然后看看要的那个,那大的块自己挑要的,然后剩下两个就你自己要全给,告诉对面每个位置要不要。
所以就是 2 3 2 n \frac{2}{3}2n 322n,那就也没问题。
(麻了不会编译,只会提交调试绷不住了)
代码
Alice
#include <iostream>
#include <fstream>
#include <string>
using namespace std;
ifstream fin;
char get_bit() {
return getchar();
}
void send_bit(char ch) {
putchar(ch);
fflush(stdout);
}
int n, m;
string s;
struct init_t {
init_t() {
fin.open("alice.in");
fin >> n >> m >> s;
}
} init_t;
int L1 = 1, R1 = 666, L2 = 667, R2 = 1332, L3 = 1333, R3 = 2000;
int main() {
// if (get_bit() == '0') {
// for (int x = 0; x < n; ++x) send_bit(s[x]);
// } else {
// for (int x = 0; x < n; ++x) send_bit(s[x + n]);
// }
s = " " + s;
int op = get_bit() - '0' + (get_bit() - '0') * 2;
if (op == 0) {
for (int i = L1; i <= R1; i++) send_bit(s[i]);
for (int i = L2; i <= R2; i++) if (get_bit() == '1') send_bit(s[i]);
for (int i = L3; i <= R3; i++) if (get_bit() == '1') send_bit(s[i]);
}
else if (op == 1) {
for (int i = L1; i <= R1; i++) if (get_bit() == '1') send_bit(s[i]);
for (int i = L2; i <= R2; i++) send_bit(s[i]);
for (int i = L3; i <= R3; i++) if (get_bit() == '1') send_bit(s[i]);
}
else if (op == 2) {
for (int i = L1; i <= R1; i++) if (get_bit() == '1') send_bit(s[i]);
for (int i = L2; i <= R2; i++) if (get_bit() == '1') send_bit(s[i]);
for (int i = L3; i <= R3; i++) send_bit(s[i]);
}
}
Bob
#include <iostream>
#include <fstream>
#include <string>
using namespace std;
ifstream fin;
char get_bit() {
return getchar();
}
void send_bit(char ch) {
putchar(ch);
fflush(stdout);
}
ofstream fout;
void answer(string s) {
fout << s << endl, exit(0);
}
const int N = 1000;
int n, m, pos[N + 1];
struct init_t {
init_t() {
int x;
fin.open("bob.in");
fout.open("bob.out");
fin >> n >> m;
for (x = 1; x <= n; ++x) fin >> pos[x];
}
} init_t;
int L1 = 1, R1 = 666, L2 = 667, R2 = 1332, L3 = 1333, R3 = 2000;
int main() {
// if (pos[n] == n) {
// send_bit('0');
// } else {
// send_bit('1');
// }
// string ans = "";
// for (int x = 0; x < n; ++x) {
// ans += get_bit();
// }
int num0 = 0, num1 = 0, num2 = 0;
for (int i = 1; i <= n; i++) {
if (L1 <= pos[i] && pos[i] <= R1) num0++;
if (L2 <= pos[i] && pos[i] <= R2) num1++;
if (L3 <= pos[i] && pos[i] <= R3) num2++;
}
string s = "";
if (num0 >= num1 && num0 >= num2) {
send_bit('0'); send_bit('0');
int now = 1;
for (int i = L1; i <= R1; i++) {
char c = get_bit();
if (now <= n && pos[now] == i) now++, s += c;
}
for (int i = L2; i <= R2; i++)
if (now <= n && pos[now] == i) now++, send_bit('1'), s += get_bit();
else send_bit('0');
for (int i = L3; i <= R3; i++)
if (now <= n && pos[now] == i) now++, send_bit('1'), s += get_bit();
else send_bit('0');
}
else if (num1 >= num0 && num1 >= num2) {
send_bit('1'); send_bit('0');
int now = 1;
for (int i = L1; i <= R1; i++)
if (now <= n && pos[now] == i) now++, send_bit('1'), s += get_bit();
else send_bit('0');
for (int i = L2; i <= R2; i++) {
char c = get_bit();
if (now <= n && pos[now] == i) now++, s += c;
}
for (int i = L3; i <= R3; i++)
if (now <= n && pos[now] == i) now++, send_bit('1'), s += get_bit();
else send_bit('0');
}
else if (num2 >= num0 && num2 >= num1) {
send_bit('0'); send_bit('1');
int now = 1;
for (int i = L1; i <= R1; i++)
if (now <= n && pos[now] == i) now++, send_bit('1'), s += get_bit();
else send_bit('0');
for (int i = L2; i <= R2; i++)
if (now <= n && pos[now] == i) now++, send_bit('1'), s += get_bit();
else send_bit('0');
for (int i = L3; i <= R3; i++) {
char c = get_bit();
if (now <= n && pos[now] == i) now++, s += c;
}
}
answer(s);
}
边栏推荐
猜你喜欢

HDRP shader to get shadows (Custom Pass)

【剑指offer】左旋字符串,替换空格,还有类题!!!

HDRP shader 获取像素深度值和法线信息

Simple interaction between server and client

MySQL性能调优,必须掌握这一个工具!!!(1分钟系列)

Primavera Unifier 高级公式使用分享

wordpress插件开发03-简单的all in one seo 插件开发

代码签名证书可以解决软件被杀毒软件报毒提醒吗?

服务器和客户端的简单交互

Segmentation Learning (loss and Evaluation)
随机推荐
Three handshakes and four waves
新一代开源免费的轻量级 SSH 终端,非常炫酷好用!
Halcon算子解释
数据库事务
大家有遇到这种错吗?flink-sql 写入 clickhouse
利用mindspore下面mindzoo里面的yolov3-darknet53进行目标识别,模型训练不收敛
网络流行简笔画图片大全,关于网络的简笔画图片
Quickly submit a PR (Web) for OpenHarmony in 5 minutes
Typescrip编译选项
canvas图片操作
最强大脑(9)
IPQ4019/IPQ4029 support WiFi6 MiniPCIe Module 2T2R 2×2.4GHz 2x5GHz MT7915 MT7975
【wxGlade学习】wxGlade环境配置
VideoScribe卡死解决方案
数据中台方案分析和发展方向
零基础创作专业wordpress网站12-设置标签栏图标(favicon)
SQL statement
HDRP Custom Pass Shader Get world coordinates and near clipping plane coordinates
snapshot standby switch
canvas文字绘制(大小、粗体、倾斜、对齐、基线)