2013-2014 ACM-ICPC, NEERC, Southern Subregional Contest Problem D. Grumpy Cat 交互题
Problem D. Grumpy Cat
题目连接:
http://www.codeforces.com/gym/100253
Description
This problem is a little bit unusual. Here you are to implement an interaction with a testing system. That
means that you can make queries and get responses in the online mode. Please be sure to use the stream
ushing operation after each query's output in order not to leave part of your output in some buer. For
example, in Ñ++ you've got to use the fflush(stdout) function, in Java call System.out.flush(),
and in Pascal flush(output).
Fall is coming and it's time to elect a new governor in Cattown. After looking at the results of the past
elections the citizens decided to nominate a new candidate Grumpy Cat. They said, all the previous
governors used to spend the Cattown's budget on their own needs and did nothing helpful for the town.
Grumpy Cat, they said, can't steal more money than he needs to feed himself.
The administration of Cattown refused to register Grumpy as a new candidate and it caused a lot of
discontent. People organized the biggest demonstration in the history of Cattown.
Your friend Eugene is a correspondent of a local newspaper. He has a work assignment to talk to
demonstrants to understand their main demands. After talking with several people Eugene realized that
each demonstrant either wants Grumpy Cat to be the new governor or doesn't want Grumpy Cat to be a
registered candidate or just wants to take part in the demonstration and doesn't have any requirements
at all. Let's call these 3 types of people grumpy-lovers, grumpy-haters and grumpy-neutral respectively. It
is known that there is at least one grumpy-lover and at least one grumpy-hater among the demonstrants.
Eugene decided to nd a type of each demonstrant. He can choose a group of demonstrants and ask them
for a number of Grumpy Cat supporters among the group. The people of Cattown don't like journalists,
reporters and correspondents. Each time Eugene asks a group of people, they proceed as follows:
- They talk to each other to understand who is who there. For sure, all grumpy-lovers are counted as
Grumpy Cat supporters and grumpy-haters are not. - If there are more grumpy-lovers than grumpy-haters in this group, all grumpy-neutrals express
support of Grumpy Cat at the time of this survey. - If there are more grumpy-haters than grumpy-lovers in this group, all grumpy-neutral people do not
support Grumpy Cat at the time of this survey. - If there are equal numbers of grumpy-haters and grumpy-lovers in this group, each grumpy-neutral
demonstrant at the time of this survey decides to support or not to support independently on his
own account. - After all grumpy-neutral people decide their position regarding Grumpy Cat, somebody tells the
correspondent the number of supporters.
A fact that a grumpy-neutral person has supported or hasn't supported Grumpy Cat doesn't aect its
decision in the future. Eugene can think that the surveys are completely independent.
Eugene doesn't have much time to do too many surveys. He can do at most ⌊
2πn
3
⌋ surveys, where π is
the ratio of a circle's circumference to its diameter and ⌊x⌋ is x rounded down. It seems too dicult for
him! Help him and write a program to interact with demonstrants to nd the type of each demonstrant.
Eugene knows that there is at least one grumpy-lover and there is at least one grumpy-hater among the
demonstrants.
Input
To read answers to the queries your program should use standard input.
The input starts with a line containing a positive integer t the number of testcases in the test.
Each testcase starts with a line containing a single integer n (2 ≤ n ≤ 100) the number of demonstrants.
The following lines will contain one integer each the number of Grumpy Cat supporters according to
the preceding survey.
The total number of demonstrants in all testcases in the test doesn't exceed 1000
Output
The program should use the standard output to print queries. Each query describes a single survey. It
should contain exactly two lines: the rst line should contain g (1 ≤ g ≤ n) the number of demonstrants
in an interviewed group, the second line should contain g distinct positive integer numbers t1, t2, . . . , tg
(1 ≤ ti ≤ n) the numbers of the demonstrants in the group. The demonstrants are numbered from 1
to n.
After your program found the types of all the demonstrants it should print exactly two lines: the rst line
should contain the only integer -1, the second line should contain exactly n integer numbers f1, f2, . . . , fn
(1 ≤ fi ≤ 3), where fi = 1 if the i-th demonstrant is a grumpy-lover, fi = 2 if the i-th demonstrant is a
grumpy-hater and fi = 3 in case of the i-th demonstrant is grumpy-neutral.
After the output of each line your program should execute the flush operation. Use single space to
separate integers in a line. Each line should end with end-of-line.
The program should write queries for the succeeding testcase after printing two lines described in the
second paragraph for the previous testcase. The program should terminate normally after the last testcase.
Sample Input
2
3
2
1
0
5
0
3
Sample Output
3
1 2 3
3
1 2 3
1
2
-1
1 2 3
3
2 4 3
3
5 3 1
-1
1 2 3 2 3
Hint
题意
有三种人,一种是兹瓷的人,一种是不兹瓷的人,和一种摇摆不定的人。
你每次可以询问一个集合,问这个集合的人里面有多少个兹瓷的人。
摇摆不定的人会哪边人多,兹瓷哪边。如果一样多,就随便回答。
然后你最多问2n次,让你确定所有人的身份。
题解:
先每个人都问一遍,这样你可以把所有人分成两类:兹瓷和摇摆的集合A,不支持和摇摆的集合B。
然后对于每一个集合A的元素都和集合B的所有人问一遍,如果有一个兹瓷的,说明那个人是兹瓷,否则就是摇摆不定的。
反之同理。
代码
#include<bits/stdc++.h>
using namespace std;
const int maxn = 1005;
int ans[maxn];
void solve()
{
memset(ans,0,sizeof(ans));
int n;
scanf("%d",&n);
vector<int> A;A.clear();
vector<int> B;B.clear();
for(int i=1;i<=n;i++)
{
printf("1\n%d\n",i);
fflush(stdout);
int x;scanf("%d",&x);
if(x==1)A.push_back(i);
else B.push_back(i);
}
for(int i=0;i<A.size();i++)
{
printf("%d\n",1+B.size());
fflush(stdout);
printf("%d",A[i]);
fflush(stdout);
for(int j=0;j<B.size();j++)
printf(" %d",B[j]),fflush(stdout);
printf("\n");
fflush(stdout);
int x;scanf("%d",&x);
if(x==0)ans[A[i]]=3;
else ans[A[i]]=1;
}
for(int i=0;i<B.size();i++)
{
printf("%d\n",1+A.size());
fflush(stdout);
printf("%d",B[i]);
fflush(stdout);
for(int j=0;j<A.size();j++)
printf(" %d",A[j]),fflush(stdout);
printf("\n");
fflush(stdout);
int x;scanf("%d",&x);
if(x==A.size()+1)ans[B[i]]=3;
else ans[B[i]]=2;
}
printf("-1\n");fflush(stdout);
for(int i=1;i<=n;i++)
{
if(i==1)printf("%d",ans[i]);
else printf(" %d",ans[i]);
fflush(stdout);
}
printf("\n");
fflush(stdout);
}
int main()
{
int t;
scanf("%d",&t);
while(t--)solve();
return 0;
}
2013-2014 ACM-ICPC, NEERC, Southern Subregional Contest Problem D. Grumpy Cat 交互题的更多相关文章
- 2010-2011 ACM-ICPC, NEERC, Moscow Subregional Contest Problem K. KMC Attacks 交互题 暴力
Problem K. KMC Attacks 题目连接: http://codeforces.com/gym/100714 Description Warrant VI is a remote pla ...
- 2018-2019 ICPC, NEERC, Southern Subregional Contest
目录 2018-2019 ICPC, NEERC, Southern Subregional Contest (Codeforces 1070) A.Find a Number(BFS) C.Clou ...
- Codeforces 2018-2019 ICPC, NEERC, Southern Subregional Contest
2018-2019 ICPC, NEERC, Southern Subregional Contest 闲谈: 被操哥和男神带飞的一场ACM,第一把做了这么多题,荣幸成为7题队,虽然比赛的时候频频出锅 ...
- 2018-2019 ICPC, NEERC, Southern Subregional Contest (Online Mirror) Solution
从这里开始 题目列表 瞎扯 Problem A Find a Number Problem B Berkomnadzor Problem C Cloud Computing Problem D Gar ...
- Codeforces1070 2018-2019 ICPC, NEERC, Southern Subregional Contest (Online Mirror, ACM-ICPC Rules, Teams Preferred)总结
第一次打ACM比赛,和yyf两个人一起搞事情 感觉被两个学长队暴打的好惨啊 然后我一直做傻子题,yyf一直在切神仙题 然后放一波题解(部分) A. Find a Number LINK 题目大意 给你 ...
- codeforce1070 2018-2019 ICPC, NEERC, Southern Subregional Contest (Online Mirror, ACM-ICPC Rules, Teams Preferred) 题解
秉承ACM团队合作的思想懒,这篇blog只有部分题解,剩余的请前往星感大神Star_Feel的blog食用(表示男神汉克斯更懒不屑于写我们分别代写了下...) C. Cloud Computing 扫 ...
- 2018-2019 ICPC, NEERC, Southern Subregional Contest (Online Mirror, ACM-ICPC Rules, Teams Preferred)
A. Find a Number 找到一个树,可以被d整除,且数字和为s 记忆化搜索 static class S{ int mod,s; String str; public S(int mod, ...
- 2018.10.20 2018-2019 ICPC,NEERC,Southern Subregional Contest(Online Mirror, ACM-ICPC Rules)
i207M的“怕不是一个小时就要弃疗的flag”并没有生效,这次居然写到了最后,好评=.= 然而可能是退役前和i207M的最后一场比赛了TAT 不过打得真的好爽啊QAQ 最终结果: 看见那几个罚时没, ...
- 2018-2019 ICPC, NEERC, Southern Subregional Contest (Online Mirror, ACM-ICPC Rules, Teams Preferred) Solution
A. Find a Number Solved By 2017212212083 题意:$找一个最小的n使得n % d == 0 并且 n 的每一位数字加起来之和为s$ 思路: 定义一个二元组$< ...
随机推荐
- Parquet 格式文件
Apache Parquet是Hadoop生态圈中一种新型列式存储格式,它可以兼容Hadoop生态圈中大多数计算框架(Hadoop.Spark等),被多种查询引擎支持(Hive.Impala.Dril ...
- 那些年的 网络通信之 TCP/IP 传输控制协议 ip 加 端口 客户端上传文件到服务器端服务器端返回上传成功消息
多线程开启, 客户端通过 Socket 流 上传文件到服务端的一个小程序练习. 1. 抓住阻塞式方法,去调试 2. 获取对应流对象操作对应的对象 这时候自己不能懵,一定要清晰,最好命名就能区别,一搞混 ...
- 小议 开源中国 I LOVE YOU js代码
今天在开源中国看到一篇神作<I LOVE YOU js代码>是17号的文章了,也许你已经看过了. 文章非常有意思,由 5 个 "爱心" 组成的一段js代码,能正常执行, ...
- 本日吐槽!“人傻钱多”的P2P公司是否是程序员的合适选择(群聊天记录的娱乐)
这个题目“P2P的职位是否是程序员的合适选择”这个问题本身是没啥可以吐槽的 但是每当我们讨论那种类型的公司工资愿意给前端工程师开的最高的时候,P2P这个行业被第一个提出了 目前我收到过面试的企业类型千 ...
- [转载]win7休眠后网络断开怎么办?如何设置?
http://jingyan.baidu.com/article/8065f87fc87d0423312498af.html 有时会遇到在Windows7系统休眠模式下会自动断开网络连接,唤醒系统也是 ...
- [整理]Assembly中的DLL提取
当机器上安装一些程序后,Assembly中的DLL会变得越来越丰富. 拿个常见问题来说明. 安装ReportViewer后其中会出现以下DLL. Microsoft.ReportViewer.Proc ...
- 五行代码终极完美解决从IE6到Chrome所有浏览器的position:fixed;以及闪动问题
这个方法其实已经使用很久了,之前主要在嵌入式WebQQ等产品中用过,现在拿出来分享一下吧,是目前最简洁的方式来实现ie6的position:fixed; 失效bug,以及的其他方法的闪动问题,CSS代 ...
- C# p2p UDP穿越NAT,UDP打洞源码
思路如下(参照源代码): 1. frmServer启动两个网络侦听,主连接侦听,协助打洞的侦听. 2. frmClientA和frmClientB分别与frmServer的主连接保持联系. 3. 当f ...
- JS中字符串那些事~
1:字符串 JS中的任何数据类型都可以当作对象来看.所以string既是基本数据类型,又是对象. 2:声明字符串 var sStr = ‘字符串’;(常用) var oStr = new String ...
- Linux 串口、usb转串口驱动分析(2-1) 【转】
转自:http://blog.chinaunix.net/xmlrpc.php?r=blog/article&uid=26807463&id=4186851 Linux 串口.usb转 ...