1241-Distribution
内存限制:64MB 时间限制:1000ms Special Judge: No
题目描述:
One day , Wang and Dong in the Dubai desert expedition, discovered an ancient castle. Fortunately, they found a map of the castle.The map marks the location of treasures.
They agreed to distribute the treasures according to the following rules:
Wang draws a horizontal line on the map and then Dong draws a vertical one so that the map is divided into 4 parts, as show below.

Wang will save the treasures in I and III ,while those situated in II and IV will be taken away by Dong.Wang first draw a horizontal line, Dong after the draw a vertical line.
They drew several pairs of lines. For each pair, Wang wants to know the difference between their treasures.
It's guaranteed that all the reasures will lie on neither of the lines drew by them.
输入描述:
输出描述:
样例输入:
10 3 29 2217 14 18 233 156 2830 274 126 78 011 212 255 1019 24
样例输出:
-644
提示:
来源
这道题很简单,只要根据给的点判断宝藏在第几象限就行了。
import java.util.Scanner;
public class Main {
public static void main(String[] args) {
Scanner sc=new Scanner(System.in);
while(sc.hasNext()){
int n=sc.nextInt();
int m=sc.nextInt();
int[][] c=new int[n][2];
for(int i=0;i<n;i++){
c[i][0]=sc.nextInt();
c[i][1]=sc.nextInt();
}
for(int i=0;i<m;i++){
int a=sc.nextInt();
int b=sc.nextInt();
int I=0,II=0,III=0,IV=0;
for(int j=0;j<n;j++){
if(c[j][0]>a&&c[j][1]>b)//宝藏在第一象限
I++;
else if(c[j][0]<a&&c[j][1]>b)//宝藏在第二象限
II++;
else if(c[j][0]<a&&c[j][1]<b)//宝藏在第三象限
III++;
else if(c[j][0]>a&&c[j][1]<b)//宝藏在第四象限
IV++;
}
System.out.println(I+III-II-IV);
}
}
}
}