zoukankan      html  css  js  c++  java
  • Codeforces Round #499 (Div. 2)D. Rocket

    题目连接:D. Rocket

    题意:交互题,让你猜一个数字, 你每次询问一个数字,他会告诉你是大还是小,但是他回答不一定正确,有一个序列p,当p[i]为1时他会回答正确的,否则错误。询问次数<60,

    题解:很明显的二分,但是p的长度有限<30我们可以通过一直猜1先把p[i]数组猜出来,然后在二分询问就可以了2^30>1e5

    #include<bits/stdc++.h>
    #include<set>
    #include<cstdio>
    #include<iomanip>
    #include<iostream>
    #include<string>
    #include<cstring>
    #include<algorithm>
    #define pb push_back
    #define ll long long
    #define fi first
    #define se second
    #define PI 3.14159265
    #define ls l,m,rt<<1
    #define rs m+1,r,rt<<1|1
    #define eps 1e-7
    #define pii pair<int,int>
    typedef unsigned long long ull;
    const int mod=1e3+5;
    const ll inf=0x3f3f3f3f3f3f3f;
    const int maxn=1e5+5;
    using namespace std;
    int n,k,m;
    int op[100];
    int main()
    {
        ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
        cin>>m>>n;
        int x;
        for(int i=1;i<=n;i++)
        {
            cout<<1<<endl;
            cout.flush();
            cin>>x;
            if(x==0)exit(0);
            else if(x==1)op[i]=1;
            else op[i]=0;
        }
        int l=1,r=m;int cn=1;
        while(l<=r)
        {
            int mid=(l+r)>>1;
            cout<<mid<<endl;
            cout.flush();
            cin>>x;
            if(x==0)exit(0);
            if(op[cn])
            {
                if(x==1)l=mid+1;
                else r=mid-1;
            }
            else
            {
                if(x!=1)l=mid+1;
                else r=mid-1;
            }
            cn++;
            if(cn>n)cn-=n;
        }
        return 0;
    }
  • 相关阅读:
    用nodejs 开发的智能提示
    分布式系统之消息中间件rabbitmq
    理解RESTful架构
    zf框架的思想及学习总结
    php网上支付易宝
    phpstorm使用技巧
    phpstorm使用技巧
    mysql中的数据类型
    CF113D 高斯消元、dp
    bzoj4008: [HNOI2015]亚瑟王 dp
  • 原文地址:https://www.cnblogs.com/lhclqslove/p/9377124.html
Copyright © 2011-2022 走看看