TTTTTTTTTTTTTTTTT Gym 100851J Jump 构造
Problem J. Jump
Input file: standard input
Output file: standard output
Consider a toy interactive problem OneMax which is defined as follows. You know an integer n and
there is a hidden bit string S of length n. The only thing you may do is to present the system a bit
string Q of length n, and the system will return the number OneMax(Q) — the number of bits which
coincide in Q and S at the corresponding positions. The name of OneMax problem stems from the fact
that this problem is simpler to explain when S = 111 . . . 11, so that the problem turns into maximization
(Max) of the number of ones (One).
When n is even, there is a similar (but harder) interactive problem called Jump. The simplest way to
describe the Jump is by using OneMax:
Jump(Q) = (
OneMax(Q) if OneMax(Q) = n or OneMax(Q) = n/2;
0 otherwise.
Basically, the only nonzero values of OneMax which you can see with Jump are n (which means you’ve
found the hidden string S) and n/2.
Given an even integer n — the problem size, you have to solve the Jump problem for the hidden string
S by making interactive Jump queries. Your task is to eventually make a query Q such that Q = S.
Interaction protocol
First, the testing system tells the length of the bit string n. Then, your solution asks the queries and
the system answers them as given by the Jump definition. When a solution asks the query Q such that
Q = S, the system answers n and terminates, so if your solution, after reading the answer n, tries reading
or writing anything, it will fail.
The limit on the number of queries is n + 500. If your solution asks a (n + 501)-th query, then you will
receive the “Wrong Answer” outcome. You will also receive this outcome if your solution terminates too
early.
If your query contains wrong characters (neither 0, nor 1), or has a wrong length (not equal to n), the
system will terminate the testing and you will receive the “Presentation Error” outcome.
You will receive the “Time Limit Exceeded” outcome and other errors for the usual violations.
Finally, if everything is OK (e.g. your solution finds the hidden string) on every test, you will receive the
“Accepted” outcome, in this case you will have solved the problem.
Input
The first line of the input stream contains an even number n (2 ≤ n ≤ 1000). The next lines of the input
stream consist of the answers to the corresponding queries. Each answer is an integer — either 0, n/2,
or n. Each answer is on its own line.
Output
To make a query, print a line which contains a string of length n which consists of characters 0 and 1
only. Don’t forget to put a newline character and to flush the output stream after you print your query.
Sample input and output
standard input standard output
题意:首先你输入一个数字n(偶数)(n<=1000),电脑则自动生成一个长度为n的01字符串,你每次可以构造出一个长度为n的01字符串,输入给电脑后电脑进行判定,如果你的字符串与电脑的字符串完全吻合,电脑返回n,如果只有一半吻合,电脑返回n/2,此外电脑返回0;你最多询问n+500次;
#include <iostream>
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <cmath>
#include <vector>
#include <queue>
#include <map>
#include <time.h>
#include <algorithm>
#include <set>
#define MM(a,b) memset(a,b,sizeof(a))
typedef long long ll;
typedef unsigned long long ULL;
const double eps = 1e-8;
const int inf = 0x3f3f3f3f;
const double pi=acos(-1);
using namespace std;
const int N=1e3+8; char a[N];
int flag[N]; void revse(int i)
{
a[i]=!(a[i]-'0')+'0';
} int main()
{
int n,x;
while(~scanf("%d",&n))
{
MM(a,'\0');
MM(flag,0);
srand(time(0));
while(1)
{
for(int i=1;i<=n;i++) a[i]=rand()%2+'0';
printf("%s\n",a+1);
fflush(stdout);
scanf("%d",&x);
if(x==n||x==n/2) break;
}
if(x==n/2)
{
revse(1);
for(int j=2;j<=n;j++)
{
revse(j);
printf("%s\n",a+1);
fflush(stdout);
scanf("%d",&x);
if(x==n) break;
else if(x==n/2) flag[j]=1;
revse(j);
}
if(x!=n)
{
revse(1);
for(int j=2;j<=n;j++) if(flag[j]) revse(j);
printf("%s\n",a+1);
fflush(stdout);
scanf("%d",&x);
if(x!=n)
{
for(int j=2;j<=n;j++) if(flag[j]) revse(j);
revse(1);
for(int j=2;j<=n;j++) if(!flag[j]) revse(j);
printf("%s\n",a+1);
fflush(stdout);
scanf("%d",&x);
}
}
}
}
return 0;
}
分析:简直神思路。首先不停播下随机数种子生成一个排列,直到系统返回n/2;得到字符串S(并不会很多,用排列组合算下) 然后将第一位数字取反,依次枚举j从2-n位,进行取反。如果最后系统还是返回n/2,说明S中第一位和第j位跟电脑的字符串匹配模式是相同的。
http://blog.csdn.net/miracle_ma/article/details/52214284
TTTTTTTTTTTTTTTTT Gym 100851J Jump 构造的更多相关文章
- 【随机化】【并查集】Gym - 100851J - Jump
题意:交互题,有一个长度为n(偶数)的二进制串,你需要猜不超过n+500次猜到它.如果你猜的串与原串相同的位数为n,那么会返回n,如果为n/2,那么会返回n/2,否则都会返回零. 先random,直到 ...
- Gym - 100851J: Jump(交互+构造+(大胆瞎搞)))
题意:给定长度为N的01串,现在让你猜这个串,猜的次数要不超过N+500次. 每次你猜一个串,系统会返回N/2,或N,或0.当且当有N/2个位置猜对,N个位置猜对,其他. 思路:因为信息不多,没有关联 ...
- Codeforces Gym 100531I Instruction 构造
Problem I. Instruction 题目连接: http://codeforces.com/gym/100531/attachments Description Ingrid is a he ...
- Tree Reconstruction Gym - 101911G(构造)
---恢复内容开始--- Monocarp has drawn a tree (an undirected connected acyclic graph) and then has given ea ...
- Gym - 101142J Java2016 (构造)
题意:给定一个数字,让你构造成一些表达式,最后结果是该数字的概率要大于50%. 析:我们可以把一个数分解是2的多少次幂,然后加起来就好. 代码如下: #pragma comment(linker, & ...
- UVaLive 6588 && Gym 100299I (贪心+构造)
题意:给定一个序列,让你经过不超过9的6次方次操作,变成一个有序的,操作只有在一个连续区间,交换前一半和后一半. 析:这是一个构造题,我们可以对第 i 个位置找 i 在哪,假设 i 在pos 位置, ...
- Painting the Fence Gym - 101911E(构造)
There is a beautiful fence near Monocarp's house. The fence consists of nn planks numbered from left ...
- Codeforces Gym 100187K K. Perpetuum Mobile 构造
K. Perpetuum Mobile Time Limit: 2 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/gym/100187/pro ...
- Codeforces Gym 100342H Problem H. Hard Test 构造题,卡迪杰斯特拉
Problem H. Hard TestTime Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/gym/100342/at ...
随机推荐
- PHP获取今日、昨日、本周、上周、本月、上月、本季、上季、今年、去年
//今天开始$beginToday = date('Y-m-d 00:00:00', time());//今天结束$endToday = date('Y-m-d 23:59:59', time()); ...
- PHP内存管理-zendMM
ZendMM 是zend memory manager zendMM可以分为三层: 1.存储层 维护者不同体量内存的hash表,已提供堆层使用,负责向os申请和释放内存 2.堆层 PHP内存管理的核心 ...
- django的admin密码忘记了怎么办?一分钟解决!!
django-admin确实是在实际开发中很方便,然后项目开发一段时间放到一边,等你再去玩你当初的项目的时候,可能抱歉你的admin密码忘记了,其实解决办法有很多种,我直说最快的一种,直接重新建立一个 ...
- Rikka with Graph hdu 6090
题解:考虑贪心地一条一条边添加进去. 当 m \leq n-1m≤n−1 时,我们需要最小化距离为 nn 的点对数,所以肯定是连出一个大小为 m+1m+1 的联通块,剩下的点都是孤立点.在这个联通块中 ...
- hdu 2610 2611 dfs的判重技巧
对于全排列枚举的数列的判重技巧 1:如果查找的是第一个元素 那么 从0开始到当前的位置看有没有出现过这个元素 出现过就pass 2: 如果查找的不是第一个元素 那么 从查找的子序列当前位置的前一个元素 ...
- css加载没效果,查看网络显示类型为 text/plain 的解决方法
当请求的css 文件的MIME 类型 为 text/plain 时,文件会当做 .txt 文件来处理,浏览器就会拒绝渲染 产生这样的问题和服务器的配置有关系 在服务器上加上下面两句就好了 搞定
- IOI2020只因训队作业胡做
w a r n i n g ! 意 识 流 警 告 !!1 不想一个个发了,干脆直接发个合集得了qwq 感觉这辈子都做不完了\(Q\omega Q\) CF516D 写过题解了 CF505E 写过题解 ...
- iot平台异构对接文档
iot平台异构对接文档 准备工作 平台提供的XAgent开发指南.pdf demo程序xagent-ptp-demo 平台上添加产品得到产品id和key 部署时需要插件的基础程序<xlink-x ...
- java读取串口-mfz-rxtx-2.2-20081207-win-x86
1.下载jar包 RXTXcomm.jar 2.实现代码 package main; import java.awt.*; import java.awt.event.*; import java.i ...
- h5嵌套iframe实时传参(适用vue)
今天看到一个同事研究给iframe传参,由于好奇,我自己也写了个demo,说起来其实也挺简单的,但是在此之前没有用过,便想记录一下 其中主要用到的是postMessage 在页面中引入一个iframe ...