区域内点的个数_JAVA
生活随笔
收集整理的這篇文章主要介紹了
区域内点的个数_JAVA
小編覺得挺不錯的,現(xiàn)在分享給大家,幫大家做個參考.
Description
X晚上睡不著的時候不喜歡玩手機,也不喜歡打游戲,他喜歡數(shù)星星。
Input
多組輸入。
每組先輸入一個整數(shù)N(N <= 10000),接著輸入兩個點代表矩形的左下點B(x,y)和右上點T(x,y),然后輸入N個(X,Y)代表N顆星星。問有多少顆星星在窗子內(nèi)部,在窗邊上的不計。
Output
輸出一個整數(shù),代表有多少顆星星在窗子內(nèi)部。
Sample
Input
3
0 1
3 4
1 1
2 2
3 3
2
1 1
5 5
4 4
0 6
Output
1
1
import java.util.*;class Area {int a, b, c, d;public Area(int a, int b, int c, int d) {this.a = a;this.b = b;this.c = c;this.d = d;}public boolean judge(int x, int y) {if (x > a && x < c && y > b && y < d) {return true;}return false;} }public class Main {public static void main(String[] args) {Scanner reader = new Scanner(System.in);while (reader.hasNext()) {int n = reader.nextInt();int sum = 0;Area area = new Area(reader.nextInt(), reader.nextInt(), reader.nextInt(), reader.nextInt());while (n-- > 0) {int x = reader.nextInt();int y = reader.nextInt();if (area.judge(x, y))sum++;}System.out.println(sum);}reader.close();} }總結(jié)
以上是生活随笔為你收集整理的区域内点的个数_JAVA的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 3-1 Point类的构造函数_JAVA
- 下一篇: 谁是最强的女汉子_JAVA