zoukankan      html  css  js  c++  java
  • 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
    ",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
    ",(x0+x1)/2,(y0+y1)/2,(z0+z1)/2);
    
        return 0;
    }
    View Code
    #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
    ",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
    ",x,y,z);
    
        return 0 ;
    
    }
    View Code
  • 相关阅读:
    sql语句游标的写法
    oracle的安装与plsql的环境配置
    oracle中创建表时添加注释
    jsp中Java代码中怎么获取jsp页面元素
    sql模糊查询
    jQuery循环给某个ID赋值
    Codeforces Round #671 (Div. 2)
    TYVJ1935 导弹防御塔
    Educational Codeforces Round 95 (Rated for Div. 2)
    Codeforces Round #670 (Div. 2)
  • 原文地址:https://www.cnblogs.com/zhgyki/p/10455617.html
Copyright © 2011-2022 走看看