Distribution(F题)---第八届河南省程序设计大赛
Description
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 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.
Input
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 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.
Output
Output contains M lines , a single line with a integer , the difference described above.
Sample Input
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
Sample Output
-6 4 4
这一题当时是第一个做的,并且一血使我们学校的一个队拿的,应该是道签到题吧
题意:给你n个点代表treasure的位置,然后再给你m个点,每给一个点时,都已这个点画一个十字架,其中位于第一部分和第三部分的是Wang的treasure共有p个,第二部分和第四部分是Dong的
共有q个,最终求他俩的差值即p-q;
#include<iostream> #include<stdio.h> #include<algorithm> #define N 1100 using namespace std; struct node { int x,y; }; int main() { int n,m,i,j,x,y,p,q; node a[N]; while(scanf("%d%d",&n,&m)!=EOF) { for(i=0;i<n;i++) { scanf("%d%d",&a[i].x,&a[i].y); } for(i=0;i<m;i++) { p=q=0; scanf("%d%d",&x,&y); for(j=0;j<n;j++) { if((a[j].x>x&&a[j].y>y)||(a[j].x<x&&a[j].y<y))//Wang的点的个数 p++; else q++;Dong的点的个数 } printf("%d\n",p-q); } } return 0; }