zoukankan      html  css  js  c++  java
  • Point on the plane (square)

    Description


    Given a square and several points, find the number of points in the square (including points on the sides of the square). Here the four sides of the square are parallel to the (x) and (y) coordinate axes.

    Format


    Input

    The four integers (x), (y), (l), and (n) in the first line are the (X) and (Y) coordinates of the lower left corner of the square, side length and the number of points ((-10000≤x,y≤10000),(l≤10000),(n≤10000));
    The next (n) lines have two numbers (x_i) and (y_i), which represent the coordinates of each point, (-10000≤x_i, y_i≤10000).

    Output

    An integer representing the number of points contained in the square.

    Sample


    Input

    0 0 5 5
    1 2
    3 4
    6 7
    5 3
    2 8
    

    Output

    3
    

    Sample Code


    #include <cstdio>
    inline bool btw(int a, int b, int c){
    	return a>=b && a<=c;
    }
    int main(){
        freopen("square.in", "r", stdin);
        freopen("square.out", "w", stdout);
        int x, y, l, n;
        scanf("%d %d %d %d", &x, &y, &l, &n);
        int ans=0;
        while (n--){
    		int u, v;
    		scanf("%d %d", &u, &v);
    		ans+= (btw(u, x, x+l) && btw(v, y, y+l));
    	}
    	printf("%d
    ", ans);
        return 0;
    }
    
  • 相关阅读:
    Queue Aizu
    Stack Aizu
    Stack Aizu
    Shell Sort Aizu
    Shell Sort Aizu
    Stable Sort Aizu
    VS2013下.Net Framework4配置FineUI4.14
    VS2013下.Net Framework4配置FineUI4.14
    Ubuntu-14.04.1 desktop安装时遇到的小问题
    Ubuntu-14.04.1 desktop安装时及安装后遇到的小问题
  • 原文地址:https://www.cnblogs.com/jiupinzhimaguan/p/13806404.html
Copyright © 2011-2022 走看看