zoukankan      html  css  js  c++  java
  • HDOJ 1577 WisKey的眼神

    WisKey的眼神

    Time Limit: 1000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)
    Total Submission(s): 1735    Accepted Submission(s): 522


    Problem Description
    WisKey的眼镜有500多度,所以眼神不大好,而且他有个习惯,就是走路喜欢看着地(不是为了拣钱哦^_^),所以大家下次碰见他的时候最好主动打下招呼,呵呵.
    但是Rabbit总是喜欢扮神秘,一天WisKey去食堂排队等着买饭,突然收到一道短消息,是Rabbit发的,”呵呵,又看见你了,你没看到我吧”.WisKey马上拉长脖子扫描食堂,可是就是看不到,再发短信问Rabbit在哪,Rabbit回信曰”我已经在寝室了”.WisKey无语....
    假设食堂是个正方形,食堂中心坐标为(0,0),长度为2*L, WisKey保证在食堂内.
    因为是吃饭高峰期,所以每个点上都站着人,当某些人处在同一直线上时就有可能被前面的人挡住.
    聪明的ACMer请你帮帮WisKey,告诉他能不能看见Rabbit.
    HDOJ 1577 WisKey的眼神 - qhn999 - 码代码的猿猿
     

    Input
    输入L,sx,sy,px,py; L<=1000,sx,sy是WisKey的坐标,px,py是Rabbit的坐标.
    以L=0为结束.
     

    Output
    对于每组输入数据,能看见输出”Yes”,看不见输出”No”.
    Rabbit不在食堂输出”Out Of Range”.
     

    Sample Input
    5 0 0 1 15 0 0 2 05 0 0 6 65 0 0 -1 -10
     

    Sample Output
    YesNoOut Of RangeYes
     

    Source
     

    Recommend
    lcy

    GCD的应用 

    #include <iostream>
    #include <cmath>

    using namespace std;

    int gcd(int a,int b)
    {
        if(a<b)  swap(a,b);
        int t=a%b;
        while(t!=0)
        {
          a=b;
          b=t;
          t=a%b;
        }
        return b;
    }

    int l,sx,sy,px,py;

    int main()
    {
        while(cin>>l&&l)
        {
            cin>>sx>>sy>>px>>py;
            if(abs(sx)>l||abs(sy)>l||abs(px)>l||abs(py)>l)
                cout<<"Out Of Range"<<endl;
            else
            {
                int x=px-sx;
                int y=py-sy;
                if(y==0||x==0)
                {
                    if(y==0&&x!=0)
                    {
                        if(x==1||x==-1)
                            cout<<"Yes"<<endl;
                        else
                            cout<<"No"<<endl;
                    }
                    else if(x==0&&y!=0)
                    {
                        if(y==1||y==-1)
                            cout<<"Yes"<<endl;
                        else
                            cout<<"No"<<endl;
                    }
                    else if(x==0&&y==0)
                    {
                        cout<<"Yes"<<endl;
                    }
                }

                else
                {
                    x=abs(x);y=abs(y);
                    int t=gcd(x,y);
                    if((x==x/t)&&(y=y/t))
                        cout<<"Yes"<<endl;
                    else
                        cout<<"No"<<endl;
                }
            }
        }
        return 0;
    }

  • 相关阅读:
    hdu 1199 Color the Ball 离散线段树
    poj 2623 Sequence Median 堆的灵活运用
    hdu 2251 Dungeon Master bfs
    HDU 1166 敌兵布阵 线段树
    UVALive 4426 Blast the Enemy! 计算几何求重心
    UVALive 4425 Another Brick in the Wall 暴力
    UVALive 4423 String LD 暴力
    UVALive 4872 Underground Cables 最小生成树
    UVALive 4870 Roller Coaster 01背包
    UVALive 4869 Profits DP
  • 原文地址:https://www.cnblogs.com/CKboss/p/3351069.html
Copyright © 2011-2022 走看看