cf 1114E

为什么这道题我到现在才写题解。。。

题解:

因为是随机题吗,,好像对于我来说还是很新颖的,就写一下。

rand()的范围是到32768?这个以前踩过坑

#include <bits/stdc++.h>
#define random(x) (1ll*rand()*rand()%x)
using namespace std;
int ask(int x){
    printf("> %d\n",x);
    fflush(stdout);
    int tmp;scanf("%d",&tmp);
    return tmp;
}
int getmax() {
    int l = 0, r = 1e9,ans=-1;
    while (l<=r){
        int mid=l+r>>1;
        if(ask(mid)){
            ans=mid+1;
            l=mid+1;
        } else{
            r=mid-1;
        }
    }
    return ans;
}
int get(int id){
    printf("? %d\n",id);
    fflush(stdout);
    int tmp;scanf("%d",&tmp);
    return tmp;
}
int main(){
    int n;
    scanf("%d",&n);
    int mx = getmax();
    int cnt=0;
    int pre=-1;
    while (cnt++<28){
        int tmp=mx-get(random(n)+1);
        if(pre==-1)
            pre=tmp;
        else{
            pre = __gcd(pre,tmp);
        }
    }
    printf("! %d %d\n",mx-(n-1)*pre,pre);
    fflush(stdout);
}
View Code

猜你喜欢

转载自www.cnblogs.com/MXang/p/10394575.html