POJ 2398 Toy Storage (Calculate geometric point line relationship)

Source: Internet
Author: User

Toy Storage
Time Limit: 1000MS Memory Limit: 65536K
Total Submissions: 4588 Accepted: 2718

Description

Mom and Dad had a problem:their child, Reza, never puts his toys away when he was finished playing with them. They gave Reza a rectangular box to put he toys in. Unfortunately, Reza is rebellious and obeys he parents by simply throwing he toys into the box. All the toys get mixed up, and it's 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 to the box, at least toys, then get thrown into different partitions stay separate. The box looks like this from the top:

We want for each positive integer t, such this there exists a partition with T-toys, determine how many partitions has T, Toys.

Input

The input consists of a number of cases. 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 <=) and the number of the toys are 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 both integers Ui Li, indicating that the ends of the ith cardboard are at the Coordin Ates (Ui, y1) and (Li, y2). You may assume that the cardboards does not be intersect with each of the other. The next m lines each consists of the integers Xi Yi specifying where the ith toy have landed in the box. Assume that no toy would land on a cardboard.

A line consisting of a single 0 terminates the input.

Output

For each box, first provide a header stating "box" to a line of its own. After that, there would be the one line of output per count (T > 0) of the toys in a partition. The value T is followed by a colon and a space, followed the number of partitions containing T toys. Output'll is 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 8 1 55 540) 107 90

Sample Output

Box2:5box1:42:1

Source

Tehran 2003 Preliminary

and Poj 2318 almost, is more than a straight line sort ~ and output when the number of toys in the grid decline output, no output ~

Test instructions: Or given a rectangle, inside a number of lines, guaranteed not to intersect, and then to a number of points, to determine where these points are in the area ~

PS: No space required between output instances ~

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 } - Wuyi Const intMAXN =5050; the Line LINE[MAXN]; - intANS[MAXN]; Wu intNUM[MAXN]; - BOOLCMP (line a,line B) About { $     returnA.s.x <b.s.x; - } -  - intMainvoid) A { +     intn,m,x1,y1,x2,y2,i; the     intUi,li; -      while(SCANF ("%d",&N), N) $     { thescanf"%d %d%d%d%d",&m,&x1,&y1,&x2,&y2); the          for(i =0; I < n; i++) the         { thescanf"%d%d",&ui,&Li); -Line[i] =Line (Point (Ui,y1), point (Li,y2)); in         } theLine[n] =Line (Point (X2,y1), point (X2,y2)); theSort (line,line+n+1, CMP); About         intx, y; the Point p; thememset (ans,0,sizeof(ans)); the  +          while(m--) -         { thescanf"%d%d",&x,&y);Bayip =Point (x, y); the             intL =0, r = n,tmp =0; the              while(L <=R) -             { -                 intMid = (L + r)/2; the                 if(Xmult (P,LINE[MID].S,LINE[MID].E) <0) the                 { theTMP =mid; theR = Mid-1; -                 } the                 Else theL = mid +1; the             }94ans[tmp]++; the         } thememset (NUM,0,sizeof(num)); the          for(i =0; I <= N; i++)98             if(Ans[i] >0) Aboutnum[ans[i]]++; -printf"box\n");101          for(i =1; I <= N; i++)102             if(Num[i] >0)103printf"%d:%d\n", I,num[i]);104     } the     return 0;106}

POJ 2398 Toy Storage (Calculate geometric point line relationship)

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.