It is exactly the same as 2318. The only difference is that the data is sorted and the output data is the statistical data.
The method is still the same as binary + cross product.
Toy storage
Time limit:1000 ms |
|
Memory limit:65536 K |
Total submissions:2491 |
|
Accepted:1427 |
Description
Mom and dad have a problem: their child, Reza, never puts his toys away when he is finished playing with them. they gave Reza a rectangular box to put his toys in. unfortunately, Reza 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 Reza to find his favorite toys anymore.
Reza's parents came up with the following idea. they put cardboard partitions into the box. even if Reza keeps throwing his toys into the box, at least toys that get thrown into different partitions stay separate. the box looks like this from the top:
We want for each positive integer T, such that there exists a partition with T toys, determine how should partitions have T, toys.
Input
The input consists of a number of instances. the first line consists of six integers n, m, X1, Y1, X2, y2. the number of cardboards to form the partitions is n (0 <n <= 1000) and the number of toys is given in M (0 <m <= 1000 ). the
Coordinates of the upper-left corner and the lower-right corner of the box are (x1, Y1) and (X2, Y2), respectively. the following n lines each consists of two integers UI Li, indicating that the ends of the ith cardboard is at the coordinates (ui, Y1) and
(Li, Y2 ). you may assume that the cardboards do not intersect with each other. the next M lines each consists of two integers Xi Yi specifying where the ith toy has landed in the box. you may assume that no toy will land on a cardboard.
A line consisting of a single 0 terminates the input.
Output
For each box, first provide a header stating "box" on a line of its own. after that, there will be one line of output per count (T> 0) of toys in a partition. the value T will be followed by a colon and a space, followed the number
Of partitions containing T toys. output will be sorted in ascending order of T for each box.
Sample Input
4 10 0 10 100 020 2080 8060 6040 405 1015 1095 1025 1065 1075 1035 1045 1055 1085 105 6 0 10 60 04 315 303 16 810 102 12 81 55 540 107 90
Sample output
Box2: 5Box1: 42: 1
# Include <iostream> # include <cstring> # include <cmath> # include <algorithm> using namespace STD; struct point // point {Double X, Y ;}; double xmult (const point & A, const point & B, const point & C) // cross product, when the point is at the right of the line> 0 when the point is at the left of the line <0 {return (. x-c.x) * (B. y-c.y)-(B. x-c.x) * (. y-c.y);} struct line // line {point a, B;} l [5005]; int counts [5005]; // count the number of toys dropped into each area double x_1, y_1, x_2, Y_2; int n, m; bool CMP (const line & A, const line & B) {if (. A. X! = B. a. x) return. a. x <B. a. x; elsereturn. b. x <B. b. x;} void Init () {memset (counts, 0, sizeof (counts); For (INT I = 0; I <n; I ++) {CIN> L [I]. a. x> L [I]. b. x; L [I]. a. y = Y_1; L [I]. b. y = Y_2;} l [N]. a. y = Y_1; L [N]. b. y = Y_2; L [N]. a. X = X_2; L [N]. b. X = X_2; sort (L, L + n + 1, CMP);} int binarysearch (point & P) {int low = 0, high = N, mid; while (low <= high) {mid = (low + high)/2; If (xmult (L [Mid]. a, L [Mid]. b, P)> 0) Low = Mid + 1; if (xmult (L [Mid]. a, L [Mid]. b, P) <0) High = mi D-1;} return high + 1;} void solve () {Int J; point toy; For (INT I = 1; I <= m; I ++) {CIN> toy. x> toy. y; j = binarysearch (toy); // Binary Search counts [J] ++ ;}} void output () {int z = 0; int cou = 0; sort (counts, counts + 1 + n); cout <"box" <Endl; For (INT I = 0; I <= N; I ++) {If (counts [I]> Z) {If (Z! = 0) cout <cou <Endl; cou = 1; Z = counts [I]; cout <z <":" ;}elsecou ++ ;} if (Z! = 0) cout <cou <Endl;} int main () {While (CIN> N & N) {CIN> m> X_1> Y_1> X_2> Y_2; Init (); solve (); output ();} return 0 ;}