POJ 2398 Toy Storage (computational geometry)

Source: Internet
Author: User

Test instructions: Given a rectangular box such as above, there are n lines in the middle, dividing it into n+1 area, given the coordinates of M toys, count the number of toys in each area.

Puzzle: Determine whether a point is between two segments by the slope.


/** through the slope to compare whether the point between the two segments */#include "iostream" #include "Cstdio" #include "algorithm" #include "CString" using namespace std;   const int n=1005; struct EDGEP//a dot on the edge {int x1,x2;} E[n]; struct point{int x, y;} P[n]; int cmp (EDGEP A,edgep b) {return a.x1<=b.x1;} int x1,y1,x2,y2;    BOOL Is_z (Point e1,point E2)///type Slash {if ((e1.y-e2.y) * (e1.x-e2.x) >=0) return true; else return false;}    BOOL Is_f (Point e1,point E2)//\ type Slash {if ((e1.y-e2.y) * (e1.x-e2.x) <=0) return true; else return false;} BOOL IS_INZR (point e1,point e2,point P)//on the right of the/type slash {if ((e1.y-e2.y) * (e1.x-e2.x) >=0) {if (p.x    -e2.x>0) && (E1.Y-E2.Y) * (p.x-e2.x) > (p.y-e2.y) * (e1.x-e2.x)) return true; } return false;} BOOL IS_INFL (point e1,point e2,point P)//on the left of the \ type slash {if ((e1.y-e2.y) * (e1.x-e2.x) <=0) {if (p.x- e2.x<0) && (E1.Y-E2.Y) * (p.x-e2.x) &Lt; (p.y-e2.y) * (e1.x-e2.x)) return true; } return false;} BOOL Is_in (Point e1,point e2,point e3,point e4,point P)//points are within the two lines {if (Is_z (e1,e2) &AMP;&AMP;IS_INZR (E1,e2,    p)) && (Is_f (e3,e4) &AMP;&AMP;IS_INFL (e3,e4,p))//point in the/.\ type of two lines return true; if ((Is_z (e1,e2) &AMP;&AMP;IS_INZR (e1,e2,p)) && (Is_z (e3,e4) &AMP;&AMP;!IS_INZR (e3,e4,p)))//point in/./type between two lines retur    n true;  if ((Is_f (e1,e2) &AMP;&AMP;!IS_INFL (e1,e2,p)) && (Is_f (e3,e4) &AMP;&AMP;IS_INFL (e3,e4,p)))//point return between two lines of the \.\ type    True if ((Is_f (e1,e2) &AMP;&AMP;!IS_INFL (e1,e2,p)) && (Is_z (e3,e4) &AMP;&AMP;!IS_INZR (e3,e4,p)))//point in \./type between two lines retur    n true; return false;}    int main () {int n,m;        while (cin>>n) {if (n==0) return 0;        e[0].x1=0,e[0].x2=0;        cin>>m>>x1>>y1>>x2>>y2;        for (int i=1;i<=n;i++) {scanf ("%d%d", &e[i].x1,&e[i].x2); } for (int i=0;i<m;i++) {scanf ("%d%d", &p[i].x,&p[i].y);        } e[n+1].x1=x2,e[n+1].x2=x2;        Sort (e,e+n+2,cmp);        int cnt[n];        memset (cnt,0,sizeof (CNT));                for (int i=0;i<=n;i++) {for (int. j=0;j<m;j++) {point e1,e2;                E1.x=e[i].x1,e1.y=y1;                E2.x=e[i].x2,e2.y=y2;                Point E3,e4;                E3.x=e[i+1].x1,e3.y=y1;                E4.x=e[i+1].x2,e4.y=y2; /*{cout<< ' (' <<e1.x<< ', ' <<e1.y<< ') ' << ' "<< ' (' &LT;&LT;E2.X&L                    t;< ', ' <<e2.y<< ') ' <<endl; cout<< ' (' <<e3.x<< ', ' <<e3.y<< ') ' << ' "<< ' (' <<e4.x<< ', ' < ')                    <e4.y<< ') ' <<endl;                cout<< ' (' <<p[j].x<< ', ' <<p[j].y<< ') ' <<endl;     }*/if (is_in (E1,e2,e3,e4,p[j]))           {cnt[i]++;                cout<< "CNT" <<i<< "++++++++++++++++++++++" <<endl;        }}//cout<< "-------------------------------------------" <<endl;        }/*for (int i=0;i<=n;i++) {cout<<cnt[i]<< ";        }*/sort (cnt,cnt+n+1);        Puts ("box");        int j=cnt[0],count=1;        cnt[n+1]=-10;            for (int i=1;i<=n+1;i++) {if (cnt[i]==j) {count++;                } else {if (j!=0) printf ("%d:%d\n", J,count);                J=cnt[i];            Count=1; }        }    }}




Time limit:MS Memory Limit:65536KB 64bit IO Format:%i64d &%i64u SubmitStatus

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


POJ 2398 Toy Storage (computational geometry)

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.