首页 > 其他 > 详细

loj#6566. 月之都的密码

时间:2019-02-18 23:36:22      阅读:390      评论:0      收藏:0      [点我收藏+]

搜交互题搜到的...

竟然还有这么水的交互题,赶紧过了再说

 

交互库里有一个 $[1,n]$ 到 $[1,n]$ 的双射

你可以调用 $encode(k,a[])$ 询问左边的一个大小为 $k$ 的集合 $a[]$,可以询问出 $a[]$ 对应的集合 $b[]$ ,但不告诉你 $a[],b[]$ 之间的一一对应关系

求双射,最多询问 log 次

 

sol:

log 次,显然是把二进制每一位拆开

然后就做完了。。。

技术分享图片
#include<bits/stdc++.h>
#define LL long long
#define rep(i,s,t) for(register int i = (s),i##end = (t); i <= i##end; ++i)
#define dwn(i,s,t) for(register int i = (s),i##end = (t); i >= i##end; --i)
using namespace std;
inline int read()
{
    int x=0,f=1;char ch;
    for(ch=getchar();!isdigit(ch);ch=getchar())if(ch==-)f=-f;
    for(;isdigit(ch);ch=getchar())x=10*x+ch-0;
    return x*f;
}
int ans[200010];
int main()
{
    int n = read(), T = read();
    for(int Bit=1;Bit<n;Bit<<=1)
    {
        cout << "encode ";
        int pnt = 0;
        rep(j, 0, n-1) if(j & Bit) pnt++;
        cout << pnt << " ";
        int cur = 0;
        rep(j, 0, n-1) if(j & Bit)
        {
            cur++;
            //printf(cur == pnt ? "%d\n" : "%d ",j+1);
            if(cur == pnt) cout << j+1 << endl;
            else cout << j+1 << " ";
        }
        //fflush(stdout);
        while(pnt--) ans[read()] |= Bit;
    }
    cout << "submit ";
    rep(i, 1, n)
    {
        if(i == n) cout << ans[i] + 1 << endl;
        else cout << ans[i] + 1 << " ";
    }
    return 0;
}
View Code

 

loj#6566. 月之都的密码

原文:https://www.cnblogs.com/Kong-Ruo/p/10398603.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!