Toys
Time limit:2000 ms 

Memory limit:65536 K 
Total submissions:10281 

Accepted:4924 
Description
Calculate the number of toys that land in each bin of a partitioned toy box.
Mom and dad have a problemtheir child John never puts his toys away when he is finished playing with them. they gave John a rectangular box to put his toys in, but John is rebellious and obeys his parents by simply throwing his toys into the box. all the toys get mixed up, and it is impossible for John to find his favorite toys.
John's parents came up with the following idea. they put cardboard partitions into the box. even if John keeps throwing his toys into the box, at least toys that get thrown into different bins stay separated. the following dimoshows a top view of an example toy box.
For this problem, you are asked to determine how many toys fall into each partition as John throws them into the toy box.
Input
The input file contains one or more problems. the first line of a problem consists of six integers, n m X1 Y1 X2 y2. the number of cardboard partitions is n (0 <n <= 5000) and the number of toys is m (0 <m <= 5000 ). the coordinates of the upperleft corner and the lowerright corner of the box are (x1, Y1) and (X2, Y2), respectively. the following n lines contain two integers per line, UI Li, indicating that the ends of the Ith cardboard partition is at the coordinates (ui, Y1) and (Li, Y2 ). you may assume that the cardboard partitions do not intersect each other and that they are specified in sorted order from left to right. the next M lines contain two integers per line, xj yj specifying where the Jth toy has landed in the box. the order of the toy locations is random. you may assume that no toy will land exactly on a cardboard partition or outside the boundary of the box. the input is terminated by a line consisting of a single 0.
Output
The output for each problem will be one line for each separate bin in the toy box. for each bin, print its Bin number, followed by a colon and one space, followed by the number of toys thrown into that bin. bins are numbered from 0 (the leftmost bin) to n (the rightmost bin ). separate the output of different problems by a single blank line.
Sample Input
5 6 0 10 60 03 14 36 810 1015 301 52 12 85 540 107 94 10 0 10 100 020 2040 4060 6080 80 5 1015 1025 1035 1045 1055 1065 1075 1085 1095 100
Sample output
0: 21: 12: 13: 14: 05: 10: 21: 22: 23: 24: 2
Hint
As the example between strates, toys that fall on the boundary of the box are "in" the box. give you a rectangle and use N line segments to divide the rectangle into n + 1 compartment, and then give you m points for you to count the number of interior points in each compartment. Question: This question uses the calculation of the relationship between the geometric midpoint and the position of the line segment. It uses the property of the cross product to determine the left or right of the online segment of the point, and then uses a binary search to determine the position of the point, and statistical output. AC code:
1 # include <cstdio> 2 # include <cstring> 3 4 const int Len = 5050; 5 6 struct point // The struct 7 {8 int X; 9 int y; 10}; 11 12 struct line // The struct 13 {14 point A; 15 point B; 16} line [Len]; 17 18 int ans [Len]; 19 20 int judge (line tline, point P3) // use the property of the cross product to determine whether the left side of the online segment is 21 {22 point T1, T2; 23 t1.x = p3.xtline. b. x; 24 t1.y = p3.ytline. b. y; 25 t2.x = tline. a. xtline. b. x; 26 t2.y = tline. a. ytline. b. y; 27 return t1.x * t2.yt1.y * t2.x; 28} 29 30 int divide (int l, int R, point toy) // Binary Search 31 {32 int mid = (L + r)/2; 33 If (mid = L) 34 return l; 35 if (Judge (line [Mid], toy) <0) 36 return divide (L, mid, toy); 37 else38 return divide (MID, R, toy); 39} 40 41 int main () 42 {43 int n, m, X1, Y1, X2, Y2; 44 // freopen ("in.txt", "r", stdin ); 45 while (scanf ("% d", & N )! = EOF & N) {46 scanf ("% d", & M, & X1, & Y1, & X2, & Y2 ); 47 memset (ANS, 0, sizeof (ANS); 48 for (INT I = 1; I <= N; I ++) {49 int up, low; 50 scanf ("% d", & up, & low); 51 line [I]. a. X = up; 52 line [I]. a. y = Y1; 53 line [I]. b. X = low; 54 line [I]. b. y = Y2; 55} 56 n ++; 57 line [0]. a. X = line [0]. b. X = x1; 58 line [0]. b. y = line [N]. b. y = Y2; 59 line [0]. a. y = line [N]. a. y = Y1; 60 line [N]. a. X = line [N]. b. X = x2; 61 for (INT I = 0; I <m; I ++) {62 point toy; 63 scanf ("% d", & toy. x, & toy. y); 64 ans [divide (0, N, toy)] ++; 65} 66 for (INT I = 0; I <n; I ++) {67 printf ("% d: % d \ n", I, ANS [I]); 68} 69 printf ("\ n"); 70} 71 return 0; 72}