POJ 2318 toys__ Computational geometry

Source: Internet
Author: User
Tags mul x2 y2
TOYS
Time Limit: 2000MS Memory Limit: 65536K
Total submissions: 9310 accepted: 4436

Description Calculate The number of toys that land in each bin of a partitioned toy box.
Mom and dad have a problem-their child John never puts his toys to away with finished. They gave John a rectangular box to put him toys in, but John are rebellious and obeys his parents by simply throwing his T Oys into the box. All of 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 he toys into the box, at least toys, then get thrown into different bins stay. The following diagram shows a top view of a example toy box.

For this problem, your are asked to determine how many toys in each fall as John partition throws into the Toy Box.

Input The input file contains one or more problems. The The A problem consists of six integers, N m x1 y1, x2 y2. The number of cardboard partitions is n (0 < n <= 5000) 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 are (x1,y1) and (X2,y2), respectively. The following n lines contain two integers per line, Ui Li, indicating this ends of the i-th cardboard partition are at The coordinates (UI,Y1) and (Li,y2). You could assume that the cardboard partitions does not intersect all other and that they are specified Left to right. The next m lines contain two integers per line, Xj Yj specifying the where the j-th toy has landed in the box. The order of the toy locations is random. You could 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 is one line for each separate bin in the Toy box. For each bin, print it bin number, followed by a colon and one spaces, followed by the number of toys thrown to that bin . Bins are 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 0 3 1 4 3 6 8 ten
1
5 2 1 2 8 5 5 7 9 4 10 0 1 0 of 0-A-
5
-A-a-ten. 0 (in)

Sample Output

0:2
1:1
2:1
3:1
4:0
5:1

0:2
1:2
2:2 3:2 4:2

Hint As the example illustrates, toys that fall on the boundary of the box are ' in ' box.

Source Rocky Mountain 2003
problem-solving ideas: Use the fork product to judge points in the right and left position of the line, and then use the two points to determine the point in which box, statistics can be.

#include <iostream> #include <cstdio> #include <cstring> #define MAX 5005 using namespace std;
	struct point {int x;
int y;
}point[max];
	struct line {point A;
Point B;
}line[max]; Inline Double Mul (point p0,point p1,point p2) {return ((p1.x-p0.x) * (P2.Y-P0.Y)-(p2.x-p0.x) * (P1.Y-P0.Y)), int search (in
	T X,int Y,int Lim) {int l=0;int r=lim;
	int Ans=lim;
	Point O;
	O.x=x;o.y=y;
		while (r>=l) {int m= (L+R) >>1;
		if (Mul (o,line[m].a,line[m].b) >0) l=m+1;
		    else {ans=m;
		R=m-1;
} return ans;
	int main () {int I,m,n,x1,x2,y1,y2,ans[max];
		while (scanf ("%d", &n), N) {memset (ans,0,sizeof (ans));
		scanf ("%d%d%d%d%d", &m,&x1,&y1,&x2,&y2);
			for (i=0;i<n;i++) {scanf ("%d%d", &line[i].a.x,&line[i].b.x);
		Line[i].a.y=y1;line[i].b.y=y2;
			for (i=0;i<m;i++) {scanf ("%d%d", &point[i].x,&point[i].y);
			int Num=search (POINT[I].X,POINT[I].Y,N);
		ans[num]++; for (i = 0; I <= N;i++) printf ("%d:%d\n", I, ans[i]); 
	printf ("\ n");
return 0; }


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.