Java练习 SDUT-2749_区域内点的个数

区域内点的个数

Time Limit: 1000 ms Memory Limit: 65536 KiB

Problem Description

X晚上睡不着的时候不喜欢玩手机,也不喜欢打游戏,他喜欢数星星。

Input

多组输入。
每组先输入一个整数N(N <= 10000),接着输入两个点代表矩形的左下点B(x,y)和右上点T(x,y),然后输入N个(X,Y)代表N颗星星。问有多少颗星星在窗子内部,在窗边上的不计。

Output

输出一个整数,代表有多少颗星星在窗子内部。

Sample Input

3
0 1
3 4
1 1
2 2
3 3

Sample Output

1

import java.util.*;

public class Main
{
	static int x1,y1,x2,y2;
	public static void main(String[] args)
	{
		Scanner cin = new Scanner(System.in);
		int n,t,i,x,y,num;
		while(cin.hasNextLine())
		{
			n = cin.nextInt();
			x1 = cin.nextInt();
			y1 = cin.nextInt();
			x2 = cin.nextInt();
			y2 = cin.nextInt();
			if(x1>x2)
			{
				t = x1;
				x1 = x2;
				x2 = t;
			}
			if(y1>y2)
			{
				t = y1;
				y1 = y2;
				y2 = t;
			}
			num = 0;
			for(i=0;i<n;i++)
			{
				x = cin.nextInt();
				y = cin.nextInt();
				if(judge(x,y)==1)
					num++;
			}
			System.out.println(num);
		}
		cin.close();
	}
	static int judge(int x,int y)
	{
		if(x>x1&&x<x2&&y>y1&&y<y2)
			return 1;
		return 0;
	}
}
posted @ 2018-11-08 17:39  洛沐辰  阅读(364)  评论(0编辑  收藏  举报