EOJ Monthly 2019.2 A. 回收卫星
题意:
你可以询问一个三维坐标,机器会告诉你这个坐标在不在目标圆中,
并且(0,0,0)是一定在圆上的,叫你求出圆心坐标
思路:
因为(0,0,0)一定在圆上,所以我们可以把圆心分成3个坐标轴上
就是求x的时候,其他坐标都为0,而且可以确定一个在x的正半轴,一个
在负半轴,所以我们可以二分求出
另外注意数据(l+r)是数据会超过long long
代码:
#include<bits/stdc++.h> using namespace std; typedef long long ll; const ll INF=4e9; void ask(ll x,ll y,ll z) { printf("0 %lld %lld %lld\n",x,y,z); fflush(stdout); } ll xx0() { ll l=-INF,r=0; ll op,ans; while(l<=r) { ll mid=(l+r)>>1; ask(mid,0,0); scanf("%d",&op); if(op==0) l=mid+1; else r=mid-1,ans=mid; } return ans; } ll xx1() { ll l=0,r=INF; ll op,ans; while(l<=r) { ll mid=l+r>>1; ask(mid,0,0); scanf("%d",&op); if(op==0) r=mid-1; else l=mid+1,ans=mid; } return ans; } ll yy0() { ll l=-INF,r=0; ll op,ans; while(l<=r) { ll mid=l+r>>1; ask(0,mid,0); scanf("%d",&op); if(op==0) l=mid+1; else r=mid-1,ans=mid; } return ans; } ll yy1() { ll l=0,r=INF; ll op,ans; while(l<=r) { ll mid=l+r>>1; ask(0,mid,0); scanf("%d",&op); if(op==0) r=mid-1; else l=mid+1,ans=mid; } return ans; } ll zz0() { ll l=-INF,r=0; ll op,ans; while(l<=r) { ll mid=l+r>>1; ask(0,0,mid); scanf("%d",&op); if(op==0) l=mid+1; else r=mid-1,ans=mid; } return ans; } ll zz1() { ll l=0,r=INF; ll op,ans; while(l<=r) { ll mid=l+r>>1; ask(0,0,mid); scanf("%d",&op); if(op==0) r=mid-1; else l=mid+1,ans=mid; } return ans; } int main() { ll x0,y0,x1,y1,z0,z1; x0=xx0(); x1=xx1(); y0=yy0(); y1=yy1(); z0=zz0(); z1=zz1(); printf("1 %lld %lld %lld\n",(x0+x1)/2,(y0+y1)/2,(z0+z1)/2); return 0; }
#include<bits/stdc++.h> #define ll long long using namespace std; const ll INF=2e9; ll a[5]; void ask(int tp,int m) { for(int i=1; i<=3; i++)a[i]=0; a[tp]=m; printf("0 %lld %lld %lld\n",a[1],a[2],a[3]); fflush(stdout); } ll go(int tp) { ll l=0,r=INF,mid,ans1=0,ans2=0; int op; while(l<=r) { mid=l+(r-l)/2; ask(tp,mid); scanf("%d",&op); if(op)l=mid + 1,ans1 = mid; else r=mid - 1; } l=-INF,r=0; while(l<=r) { mid=l+(r-l)/2; ask(tp,mid); scanf("%d",&op); if(op)r=mid-1,ans2 = mid; else l=mid+1; } return (ans1+ans2)/2; } int main() { ll x,y,z; x=go(1); y=go(2); z=go(3); printf("1 %lld %lld %lld\n",x,y,z); return 0 ; }