zoukankan      html  css  js  c++  java
  • Codeforces Round #512 (Div. 2)B.Vasya and Cornfield

    B. Vasya and Cornfield
    time limit per test
    1 second
    memory limit per test
    256 megabytes
    input
    standard input
    output
    standard output

    Vasya owns a cornfield which can be defined with two integers nn and dd . The cornfield can be represented as rectangle with vertices having Cartesian coordinates (0,d),(d,0),(n,nd)(0,d),(d,0),(n,n−d) and (nd,n)(n−d,n) .


    An example of a cornfield with n=7n=7 and d=2d=2 .

    Vasya also knows that there are mm grasshoppers near the field (maybe even inside it). The ii -th grasshopper is at the point (xi,yi)(xi,yi) . Vasya does not like when grasshoppers eat his corn, so for each grasshopper he wants to know whether its position is inside the cornfield (including the border) or outside.

    Help Vasya! For each grasshopper determine if it is inside the field (including the border).

    Input

    The first line contains two integers nn and dd (1d<n1001≤d<n≤100 ).

    The second line contains a single integer mm (1m1001≤m≤100 ) — the number of grasshoppers.

    The ii -th of the next mm lines contains two integers xixi and yiyi (0xi,yin0≤xi,yi≤n ) — position of the ii -th grasshopper.

    Output

    Print mm lines. The ii -th line should contain "YES" if the position of the ii -th grasshopper lies inside or on the border of the cornfield. Otherwise the ii -th line should contain "NO".

    You can print each letter in any case (upper or lower).

    Examples
    Input
    Copy
    7 2
    4
    2 4
    4 1
    6 3
    4 5
    Output
    Copy
    YES
    NO
    NO
    YES
    Input
    Copy
    8 7
    4
    4 4
    2 8
    8 1
    6 1
    Output
    Copy
    YES
    NO
    YES
    YES
    Note

    The cornfield from the first example is pictured above. Grasshoppers with indices 11 (coordinates (2,4)(2,4) ) and 44 (coordinates (4,5)(4,5) ) are inside the cornfield.

    The cornfield from the second example is pictured below. Grasshoppers with indices 11 (coordinates (4,4)(4,4) ), 33 (coordinates (8,1)(8,1) ) and 44 (coordinates (6,1)(6,1) ) are inside the cornfield.

    题意

      给一个矩形,判断下面的点是否在矩形内。

    分析

      判断点是否在上下两条边内,和左右两条边内就可以了。模板奉上。

    ///  author:Kissheart  ///
    #include<stdio.h>
    #include<algorithm>
    #include<iostream>
    #include<string.h>
    #include<vector>
    #include<stdlib.h>
    #include<math.h>
    #include<queue>
    #include<deque>
    #include<ctype.h>
    #include<map>
    #include<set>
    #include<stack>
    #include<string>
    #define INF 0x3f3f3f3f
    #define FAST_IO ios::sync_with_stdio(false)
    const double PI = acos(-1.0);
    const double eps = 1e-6;
    const int MAX=1e6+10;
    const int mod=1e9+7;
    typedef long long ll;
    using namespace std;
    #define gcd(a,b) __gcd(a,b)
    inline ll lcm(ll a,ll b){return a/gcd(a,b)*b;}
    inline ll qpow(ll a,ll b){ll r=1,t=a; while(b){if(b&1)r=(r*t)%mod;b>>=1;t=(t*t)%mod;}return r;}
    inline ll inv1(ll b){return qpow(b,mod-2);}
    inline ll exgcd(ll a,ll b,ll &x,ll &y){if(!b){x=1;y=0;return a;}ll r=exgcd(b,a%b,y,x);y-=(a/b)*x;return r;}
    inline ll read(){ll x=0,f=1;char c=getchar();for(;!isdigit(c);c=getchar()) if(c=='-') f=-1;for(;isdigit(c);c=getchar()) x=x*10+c-'0';return x*f;}
    //freopen( "in.txt" , "r" , stdin );
    //freopen( "data.txt" , "w" , stdout );
    double n,d;
    struct Point
    {
        double x;
        double y;
        Point(double x,double y)
        {
            this->x = x;
            this->y = y;
        }
    };
    double GetCross(Point& p1, Point& p2,Point& p)
    {
        return (p2.x - p1.x) * (p.y - p1.y) -(p.x - p1.x) * (p2.y - p1.y);
    }
    int IsPointInMatrix(Point& p)
    {
        Point p1(0,d);
        Point p2(d,0);
        Point p3(n,n-d);
        Point p4(n-d,n);
        return GetCross(p1,p2,p)*GetCross(p3,p4,p)>=0 && GetCross(p2,p3,p)*GetCross(p4,p1,p)>=0;
    }
    int main()
    {
        int t;
        scanf("%lf%lf",&n,&d);
        scanf("%d",&t);
        while(t--)
        {
            double x,y;
            scanf("%lf%lf",&x,&y);
            Point p(x,y);
            if(IsPointInMatrix(p)) printf("YES
    ");
            else printf("NO
    ");
        }
        return 0;
    
    }
    View Code
  • 相关阅读:
    git warning: LF will be replaced by CRLF in 解决办法
    今天买了个pro,开始ios开发
    基于pyspark的mapreduce实现
    正则表达式中全部符号作用及解释
    CNN
    tensorboard使用及tensorflow各层权重系数输出
    DeepFM tensorflow实现
    FM详解
    sklearn计算auc需要注意的点
    矩阵压缩存储(可用于FM算法中的稀疏矩阵存储)
  • 原文地址:https://www.cnblogs.com/Kissheart/p/10009879.html
Copyright © 2011-2022 走看看