POJ-2398 Toy Storage

Source: Internet
Author: User

Toy Storage

Time Limit: 1000MS Memory Limit: 65536K

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

Exercises

Same as 2318, just sort it out, and the output is different.

Code

#include <iostream>#include<stdio.h>#include<string.h>#include<math.h>#include<algorithm>using namespacestd;Const intMAXN = the+ -;intANS[MAXN];structpoint{intx, y; Point () {}, point (int_x,int_y) {x= _x;y =_y; } Pointoperator-(ConstPoint &b)Const    {        returnPoint (X-b.x,y-b.y); }    int operator*(ConstPoint &b)Const    {        returnx*b.x + y*b.y; }    int operator^(ConstPoint &b)Const    {        returnx*b.y-y*b.x; }};structline{Point S,e; Line () {} line (point _s,point _e) {s= _s;e =_e; }    BOOL operator< (ConstLine &AMP;RHS)Const{       if(s.x==rhs.s.x)returne.x<rhs.e.x; returns.x<rhs.s.x; }};intXmult (Point p0,point p1,point p2) {return(p1-p0) ^ (p2-p0);} Line LINE[MAXN];intNUM[MAXN];intMain () {intN,m,x1,x2,y1,y2;  while(SCANF ("%d", &n) = =1&&N) {scanf ("%d%d%d%d%d",&m,&x1,&y1,&x2,&y2); intUi,li;  for(intI=0; i<n;i++) {scanf ("%d%d",&ui,&Li); Line[i]=Line (Point (Ui,y1), point (Li,y2)); } Line[n]=Line (Point (X2,y1), point (X2,y2)); Sort (Line,line+n+1); intx, y;        Point P; memset (ans,0,sizeof(ans));  while(m--) {scanf ("%d%d",&x,&y); P=Point (x, y); intL=0, r=N; inttmp;  while(l<=R) {                intMid= (L+R)/2; if(Xmult (P,LINE[MID].S,LINE[MID].E) <0) {tmp=mid; R=mid-1; }                ElseL=mid+1; } Ans[tmp]++; } printf ("box\n"); memset (num,0,sizeof(num));  for(intI=0; i<=n;i++)            if(ans[i]>0) num[ans[i]]++;  for(intI=0; i<=n;i++)            if(num[i]>0) printf ("%d:%d\n", I,num[i]); }    return 0;}

POJ-2398 Toy Storage

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.