zoukankan      html  css  js  c++  java
  • loj#6566. 月之都的密码

    搜交互题搜到的...

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

    交互库里有一个 $[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
    " : "%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
  • 相关阅读:
    使用nodeJs安装Vue-cli
    Win10 下安装 NodeJS
    sublime Text 3 字体
    使用THINKPHP中的控制器和模块查询数据库
    Windows下PHP开发环境搭建
    在HTML中使用JS
    Python 网络编程介绍
    python 单例模式
    Python 元类
    Python 异常处理
  • 原文地址:https://www.cnblogs.com/Kong-Ruo/p/10398603.html
Copyright © 2011-2022 走看看