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.
II I
III IV
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 oflines. 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.
第一行两个整数n,m,第二行到n+1行是n个点的坐标,最后m行每行给出两个整数a,b分别代表x,y轴分界线。
Output contains M lines , a single line with a integer , the difference described above.
10 3
29 22
17 14
18 23
3 15
6 28
30 27
4 1
26 7
8 0
11 21
2 25
5 10
19 24
-6
4
4
水题:
#include <cstdio> #include <cstring> #include <cstdlib> using namespace std; int main() { int n, m; int x[110], y[110]; int a, b; int i, j; int sum; while(scanf("%d%d", &n, &m)!=EOF) { for(i = 0; i < n; i++) { scanf("%d%d", &x[i], &y[i]); } while(m--) { scanf("%d%d", &a, &b); sum = 0; for(i = 0; i < n; i++) { if(x[i] > a && y[i] > b || x[i] < a && y[i] < b) sum++; } printf("%d\n", sum-n+sum); } } return 0; }