TOYS (POJ 2381 cross product + two points)

Source: Internet
Author: User
Tags x2 y2

Language:DefaultTOYS
Time Limit: 2000MS Memory Limit: 65536K
Total Submissions: 11718 Accepted: 5653

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


Test instructions: Give the coordinates of M points, fall in the n+1 area, ask how many points each area has.

Idea: Use the cross product to determine which side of the line segment, two points to solve. Today began to touch the computational geometry slowly, but the network flow has not played Shunliu =-=

Code:

#include <iostream> #include <cstdio> #include <cstring> #include <algorithm> #include < cmath> #include <string> #include <map> #include <stack> #include <vector> #include <set > #include <queue> #pragma comment (linker, "/stack:102400000,102400000") #define PI ACOs ( -1.0) #define EPS 1e-6# Define Lson rt<<1,l,mid#define Rson rt<<1|1,mid+1,r#define FRE (i,a,b) for (i = A; I <= b; i++) #define FREE ( I,A,B) for (i = A, I >= b; i--) #define FRL (i,a,b) for (i = A; I < b; i++) #define FRLL (i,a,b) for (i = A; i > b; i-- ) #define MEM (T, v) memset ((t), V, sizeof (t)) #define SF (n) scanf ("%d", &n) #define SFF (A, b) scanf ("%d%d",         &a, &b) #define SFFF (a,b,c) scanf ("%d%d%d", &a, &b, &c) #define PF Printf#define DBG  PF ("hi\n") typedef long long ll;using namespace std; #define INF 0x3f3f3f3f#define mod 1000000009const int maxn = 5500;const int MAXN = 2005;const int N = 1005;int N,m;int x1,y1,x2,y2;struct point{int x, y;    Point () {}, point (int _x,int _y) {x=_x; y=_y;    } point operator-(const-point-&b) const {return point (X-B.X,Y-B.Y);    } int operator* (const point &b) const {return x*b.x+y*b.y;    } int operator^ (const point &b) const {return x*b.y-y*b.x;    }};struct line{Point S,e;    Line () {} line (point _s,point _e) {s=_s;e=_e; }};int Xmulti (Point p0,point p1,point p2)/cross product {return (P2-P0) ^ (p1-p0);}    Line Line[maxn];int ans[maxn];void solve () {int x, y;    Point P;    MEM (ans,0);        while (m--) {SFF (x, y);        P=point (x, y);        int l=0,r=n,temp;            while (l<=r) {int mid= (L+R) >>1;            if (Xmulti (P,LINE[MID].S,LINE[MID].E) <0) l=mid+1;                else {temp=mid;            R=mid-1;    }} ans[temp]++; } for (int i=0;i<=n;i++) PF ("%d:%D\n ", I,ans[i]);}    int main () {#ifndef Online_judge freopen ("C:/users/lyf/desktop/in.txt", "R", stdin), #endif int i,j;    int flag=0;        while (SF (n), N) {SF (M);        SFF (X1,Y1);        SFF (X2,Y2);        if (flag) PF ("\ n");        flag=1;        int A, B;            for (i=0;i<n;i++) {SFF (A, b);        Line[i]=line (Point (A,y1), point (B,y2));        } line[n]=line (Point (X2,y1), point (X2,y2));    Solve (); } return 0;}



Copyright NOTICE: This article for Bo Master original article, without Bo Master permission not reproduced.

TOYS (POJ 2381 cross product + two points)

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.