Description
Input
Output
Solution
这是一道交互题
就是有一颗n个点的树,让你在11111次询问内求出这棵树的结构
因为(n leqslant 500),所哟一我们可以乱搞
我们先钦定1为根,则可以用n-1次算出以i为根的子树的节点数
然后我们将节点数排序
因为每个点只有一个父亲,我们可以通过二分那些没有父亲的点来求儿子
Code
#include <cstdio>
#include <algorithm>
#define N 1001
#define open(x) freopen(x".in","r",stdin);freopen(x".out","w",stdout);
using namespace std;
int n,i,j,l,r,mid,tmp,cnt,len,sum,from[N],to[N],p[N];
bool bz[N];
struct node{
int num,id;
}tree[N];
bool cmp(node x,node y){return x.num<y.num;}
int main()
{
scanf("%d",&n);
for (i=2;i<=n;i++)
{
printf("1
1
%d
",n-1);
for (j=2;j<=n;j++)
printf("%d ",j);
printf("
%d
",i);
fflush(stdout);
scanf("%d",&tree[i].num);
tree[i].id=i;
}
tree[1].num=n;tree[1].id=1;
sort(tree+1,tree+n+1,cmp);
for (i=1;i<=n;i++)
{
if (tree[i].num==1) continue;
tmp=1;sum=1;
while (sum<tree[i].num)
{
cnt=0;
for (j=1;j<i;j++)
if (!bz[j]) p[++cnt]=j;
l=1;r=cnt;
while (l<r)
{
mid=(l+r)/2;
printf("%d
",mid-l+1);
for (j=l;j<=mid;j++)
printf("%d ",tree[p[j]].id);
printf("
%d
",1);
printf("%d
%d
",1,tree[i].id);
fflush(stdout);
scanf("%d",&tmp);
if (tmp)r=mid;else l=mid+1;
}
bz[p[l]]=1;
from[++len]=tree[i].id;to[len]=tree[p[l]].id;sum+=tree[p[l]].num;
}
}
printf("ANSWER
");
for (i=1;i<=len;i++)
printf("%d %d
",from[i],to[i]);
return 0;
}