首页 > 其他分享 >Codeforces Round #838 (Div. 2) D

Codeforces Round #838 (Div. 2) D

时间:2022-12-16 18:24:42浏览次数:66  
标签:int res 838 Codeforces gy gx 排除 Div

D. Journey to Un'Goro

题链
考虑一个三元组内一定可以排除一个非0的
x y z
我们询问x z 和 y z
要是gx==gy 那么我们的z一定不是0 否则gx=px gy=py
排除z
要是gx!=gy
那么我们z可能是0
如果z是0
gx gy 我们随便排除一个即可
如果z不是0
要是x是0
gx=pz gy=gcd(pz,py)<pz
那么我们排除更小的那个g即可

int query(int x,int y){
    cout<<"? "<<x<<' '<<y<<endl;
    int res;cin>>res;
    return res;
}
void solve(){
    int n;cin>>n;
    int x=1,y=2;
    for(int i=3;i<=n;i++){
        int gx= query(x,i);
        int gy= query(y,i);
        if(gx!=gy){
            if(gx<gy){
                x=i;
            }else{
                y=i;
            }
        }
    }
    cout<<"! "<<x<<' '<<y<<endl;
    cin>>n;
}

标签:int,res,838,Codeforces,gy,gx,排除,Div
From: https://www.cnblogs.com/ycllz/p/16988036.html

相关文章