Codeforces 1270D 思维题
This problem is interactive.
We have hidden an array aa of nn pairwise different numbers (this means that no two numbers are equal). You can get some information about this array using a new device you just ordered on Amazon.
This device can answer queries of the following form: in response to the positions of kk different elements of the array, it will return the position and value of the mm-th among them in the ascending order.
Unfortunately, the instruction for the device was lost during delivery. However, you remember kk, but don't remember mm. Your task is to find mm using queries to this device.
You can ask not more than nn queries.
Note that the array aa and number mm are fixed before the start of the interaction and don't depend on your queries. In other words, interactor is not adaptive.
Note that you don't have to minimize the number of queries, and you don't need to guess array aa. You just have to guess mm.
The first line contains two integers nn and kk (1≤k<n≤5001≤k<n≤500) — the length of the array and the number of the elements in the query.
It is guaranteed that number mm satisfies 1≤m≤k1≤m≤k, elements a1,a2,…,ana1,a2,…,an of the array satisfy 0≤ai≤1090≤ai≤109, and all of them are different.
You begin the interaction by reading nn and kk.
To ask a question about elements on positions x1,x2,…,xkx1,x2,…,xk, in a separate line output
?? x1x1 x2x2 x3x3 ... xkxk
Numbers in the query have to satisfy 1≤xi≤n1≤xi≤n, and all xixi have to be different. Don't forget to 'flush', to get the answer.
In response, you will receive two integers pospos and aposapos — the position in the array aa of the mm-th in ascending order element among ax1,ax2,…,axkax1,ax2,…,axk, and the element on this position.
In case your query is invalid or you asked more than nn queries, the program will print −1−1 and will finish interaction. You will receive a Wrong answer verdict. Make sure to exit immediately to avoid getting other verdicts.
When you determine mm, output
!! mm
After printing a query do not forget to output end of line and flush the output. Otherwise, you will get Idleness limit exceeded. To do this, use:
- fflush(stdout) or cout.flush() in C++;
- System.out.flush() in Java;
- flush(output) in Pascal;
- stdout.flush() in Python;
- see documentation for other languages.
Hack format
For the hacks use the following format:
The first line has to contain three integers n,k,mn,k,m (1≤m≤k<n≤5001≤m≤k<n≤500) — the length of the array, number of elements in the query, and which in the ascending order number the device returns.
In the next line output nn integers a1,a2,…,ana1,a2,…,an (0≤ai≤1090≤ai≤109) — the elements of the array. They have to be pairwise different.
4 3 4 9 4 9 4 9 1 2
? 2 3 4 ? 1 3 4 ? 1 2 4 ? 1 2 3 ! 3
In the example, n=4n=4, k=3k=3, m=3m=3, a=[2,0,1,9]a=[2,0,1,9].
#include<iostream> #include<cstdio> #include<cstring> using namespace std; int cnt1,cnt2,val1=-1,val2=-1; int main(){ int n,k; scanf("%d%d",&n,&k); for(int i=1;i<=k+1;i++){ printf("? "); for(int j=1;j<=k+1;j++){ if(i==j)continue; printf("%d ",j); } puts(""); fflush(stdout); int x,y; scanf("%d%d",&x,&y); if(y==val1||val1==-1){ cnt1++; val1=y; } else { cnt2++; val2=y; } } if(val1>val2) printf("! %d\n",cnt1); else printf("! %d\n",cnt2); return 0; }
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· go语言实现终端里的倒计时
· 如何编写易于单元测试的代码
· 10年+ .NET Coder 心语,封装的思维:从隐藏、稳定开始理解其本质意义
· .NET Core 中如何实现缓存的预热?
· 从 HTTP 原因短语缺失研究 HTTP/2 和 HTTP/3 的设计差异
· 分享一个免费、快速、无限量使用的满血 DeepSeek R1 模型,支持深度思考和联网搜索!
· 基于 Docker 搭建 FRP 内网穿透开源项目(很简单哒)
· ollama系列1:轻松3步本地部署deepseek,普通电脑可用
· 按钮权限的设计及实现
· 25岁的心里话
2017-02-12 2017.2.10测试 藏妹子之处