TOYS
| Time Limit: 2000MS |
|
Memory Limit: 65536K |
| Total Submissions: 12015 |
|
Accepted: 5792 |
Description
Calculate the number of toys that land in each bin of a partitioned toy box.
Mom and Dad had a problem-their child John never puts his toys away when he was finished playing with them. They gave John a rectangular box to put he toys in, but John is rebellious and obeys he parents by simply throwing he t Oys into the box. All the toys get mixed up, and it's 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 to the box, at least toys, then get thrown into different bins stay separated. The following diagram shows a top view of an example toy box.
For this problem, you is asked to determine what 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 <=) and the number of toys is m (0 < M <= 5000). The coordinates of the upper-left corner and the lower-right corner of the box is (x1,y1) and (X2,y2), respectively. The following n lines contain, integers per line, Ui Li, indicating, the ends of the i-th cardboard partition are at The coordinates (UI,Y1) and (Li,y2). Assume that the cardboard partitions does not intersect each other and that they is specified in sorted order from Left-to-right. The next m lines contain and integers per line, Xj Yj specifying where the j-th toy have landed in the box. The order of the toy locations is random. Assume that no toy would 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 would be a line for each separate bin in the Toy box. For each bin, print it bin number, followed by a colon and one space, followed by the number of the toys thrown into the bin . Bins is 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 10 75 1085 1095 100
Sample Output
0:21:12:13:14:05:10:21:22:23:24:2
Hint
As the example illustrates, toys that fall on the boundary of the box is "in" the box.
Source
Rocky Mountain 2003
To start a serious study of computational geometry, well, yes, that's right.
Cheer Up ~
Test instructions: Given a rectangle, add disjoint lines to the inside, and then give a few points to find out which area the points fall in.
1#include <iostream>2#include <cstdio>3#include <cmath>4#include <cstdlib>5#include <cstring>6#include <math.h>7#include <algorithm>8#include <cctype>9#include <string>Ten#include <map> One #defineN 500015 A #defineINF 1000000 - #definell Long Long - using namespacestd; the struct Point - { - intx, y; - Point () {} +Point (int_x,int_y) - { +x = _x;y =_y; A } atPointoperator-(ConstPoint &b)Const - { - returnPoint (X-b.x,y-b.y); - } - int operator*(ConstPoint &b)Const - { in returnx*b.x + y*b.y; - } to int operator^(ConstPoint &b)Const + { - returnx*b.y-y*b.x; the } * }; $ struct LinePanax Notoginseng { - Point s,e; the Line () {} + Line (Point _s,point _e) A { thes = _s;e =_e; + } - }; $ $ intXmult (Point p0,point p1,point p2)//calculate P0P1 X p0p2 - { - return(p1-p0) ^ (p2-p0); the } - Const intMAXN =5050;Wuyi Line LINE[MAXN]; the intANS[MAXN]; - intMainvoid) Wu { - intn,m,x1,y1,x2,y2,i; About intUi,li; $ intCNT =0; - while(SCANF ("%d",&N), N) - { - if(CNT = =0) CNT =1; A Elseprintf"\ n"); +scanf"%d %d%d%d%d",&m,&x1,&y1,&x2,&y2); the for(i =0; I < n; i++) - { $scanf"%d%d",&ui,&Li); theLine[i] =Line (Point (Ui,y1), point (Li,y2)); the } theLine[n] =Line (Point (X2,y1), point (X2,y2)); the - intx, y; in Point p; thememset (ans,0,sizeof(ans)); the About while(m--) the { thescanf"%d%d",&x,&y); thep =Point (x, y); + intL =0, r = n,tmp =0; - while(L <=R) the {Bayi intMid = (L + r)/2; the if(Xmult (P,LINE[MID].S,LINE[MID].E) <0) the { -TMP =mid; -R = Mid-1; the } the Else theL = mid +1; the } -ans[tmp]++; the } the for(i =0; I <= N; i++) theprintf"%d:%d\n", I,ans[i]);94 } the return 0; the}
Poj 2318 TOYS (calculates the relationship between geometric points and line segments)