poj2318
来源:互联网 发布:大自然音效软件 编辑:程序博客网 时间:2024/05/05 01:10
http://poj.org/problem?id=2318
TOYS
Time Limit: 2000MSMemory Limit: 65536KTotal Submissions: 6790Accepted: 3213
Description
Calculate the numberof toys that land in each bin of a partitioned toy box.
Mom and dad have a problem - their child John never puts his toysaway when he is finished playing with them. They gave John arectangular box to put his toys in, but John is rebellious andobeys his parents by simply throwing his toys into the box. All thetoys get mixed up, and it is impossible for John to find hisfavorite toys.
John's parents came up with the following idea. They put cardboardpartitions into the box. Even if John keeps throwing his toys intothe box, at least toys that get thrown into different bins stayseparated. The following diagram shows a top view of an example toybox.
For this problem, you are asked to determine how many toys fallinto each partition as John throws them into the toy box.
Mom and dad have a problem - their child John never puts his toysaway when he is finished playing with them. They gave John arectangular box to put his toys in, but John is rebellious andobeys his parents by simply throwing his toys into the box. All thetoys get mixed up, and it is impossible for John to find hisfavorite toys.
John's parents came up with the following idea. They put cardboardpartitions into the box. Even if John keeps throwing his toys intothe box, at least toys that get thrown into different bins stayseparated. The following diagram shows a top view of an example toybox.
For this problem, you are asked to determine how many toys fallinto each partition as John throws them into the toy box.
Input
The input filecontains one or more problems. The first line of a problem consistsof six integers, n m x1 y1 x2 y2. The number of cardboardpartitions is n (0 < n <= 5000) andthe number of toys is m (0 < m <=5000). The coordinates of the upper-left corner and the lower-rightcorner of the box are (x1,y1) and (x2,y2), respectively. Thefollowing n lines contain two integers per line, Ui Li, indicatingthat the ends of the i-th cardboard partition is at the coordinates(Ui,y1) and (Li,y2). You may assume that the cardboard partitionsdo not intersect each other and that they are specified in sortedorder from left to right. The next m lines contain two integers perline, Xj Yj specifying where the j-th toy has landed in the box.The order of the toy locations is random. You may assume that notoy will land exactly on a cardboard partition or outside theboundary of the box. The input is terminated by a line consistingof a single 0.
Output
The output for eachproblem will be one line for each separate bin in the toy box. Foreach bin, print its bin number, followed by a colon and one space,followed by the number of toys thrown into that bin. Bins arenumbered from 0 (the leftmost bin) to n (the rightmost bin).Separate the output of different problems by a single blankline.
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 1075 1085 1095 100
Sample Output
0: 21: 12: 13: 14: 05: 10: 21: 22: 23: 24: 2
Hint
As the exampleillustrates, toys that fall on the boundary of the box are "in" thebox.
Source
Rocky Mountain 2003
AC代码如下
#include<stdio.h>#include<string.h>#define MAXD 5010int N, M, X1, Y1, X2, Y2, a[MAXD], b[MAXD], h[MAXD];long long int det(int x1, int y1, int x2, int y2){ return (long long int)x1 * y2 - (long long int)x2 * y1;}void init(){ int i, j, k; a[0] = b[0] = X1; for(i = 1; i <= N; i ++) scanf("%d%d", &a[i], &b[i]);}void solve(){ int i, j, k, x, y, mid, min, max; memset(h, 0, sizeof(h[0]) * (N + 1)); for(i = 0; i < M; i ++) { scanf("%d%d", &x, &y); min = 0, max = N + 1; for(;;) { mid = (max - min) / 2 + min; if(mid == min) break; if(det(a[mid] - b[mid], Y1 - Y2, x - b[mid], y - Y2) < 0) min = mid; else max = mid; } ++ h[mid]; } for(i = 0; i <= N; i ++) printf("%d: %d\n", i, h[i]);}int main(){ int t = 0; while(scanf("%d%d%d%d%d%d", &N, &M, &X1, &Y1, &X2, &Y2) == 6) { if(t ++) printf("\n"); init(); solve(); } return 0;}
- poj2318
- POJ2318
- poj2318
- poj2318
- poj2318
- poj2318
- poj2318
- poj2318
- Poj2318
- poj2318
- POJ2318 TOY
- poj2318 - TOYS
- poj2318 poj2398
- poj2318 TOYS
- 【poj2318】TOYS
- [Poj2318]TOYS
- poj2318 Toys
- poj2318 TOYS
- XML解析错误:未找到元素 位置:moz-nullprincipal
- 计算几何入门题(转载)
- 学习+生活:感悟
- ExtAspNet快速入门 - 创建用户登录界面
- 杭电1086(计算几何)解题报告
- poj2318
- poj1141
- 将byte[]数组转换为图片,并在jsp页面进行显示
- 动态规划分类
- 杭电1257(DP)
- 2012年05月01日
- 七、线程调度优先级和关联性
- poj1700andpoj3404
- 合唱队列