poj 2318
来源:互联网 发布:jstor数据库中文版 编辑:程序博客网 时间:2024/06/05 04:20
题意:给出矩形的左上和右下的坐标,在矩形中有n个木棒,木棒之间不会相交,然后给出木棒上下端点的横坐标,接着有m个玩具,给出玩具的坐标。输出木棒围成的区域中有玩具的个数。
思路:由于数据范围大,所以对有序的木棒二分,叉积判断点在木棒的哪端。
#include<iostream>#include<cstdio>using namespace std;const int maxn = 5010;struct point { double x , y; };double Xmult(point a , point b , point c) { return (b.x-a.x)*(c.y-a.y) - (b.y-a.y)*(c.x-a.x);}point P[maxn] , Pu[maxn] , Pd[maxn];int sum[maxn];int n , m , k;void Bin(point X) { int l , r , ans; double tmp; l = 0; r = n+1; while(l <= r) { int mid = (l+r)/2; tmp = Xmult(X , Pu[mid] , Pd[mid]); if(tmp < 0) { ans = mid; //printf("ans = %d\n",ans); r = mid-1; } else l = mid+1; } //printf("id = %d\n",ans); sum[ans-1] ++;}int main() { double x1 , y1 , x2 , y2; int i , j; while(~scanf("%d",&n)) { if(!n) break; scanf("%d%lf%lf%lf%lf",&m,&x1,&y1,&x2,&y2); for(i = 1 ; i <= n ; i ++) { scanf("%lf%lf",&Pu[i].x,&Pd[i].x); Pu[i].y = y1; Pd[i].y = y2; } Pu[0].x = x1;Pu[0].y=y1; Pd[0].x = x1;Pd[0].y=y2; Pu[n+1].x = x2;Pu[n+1].y=y1; Pd[n+1].x = x2;Pd[n+1].y=y2; for(i = 0 ; i < m ; i ++) scanf("%lf%lf",&P[i].x,&P[i].y); k = 0; memset(sum , 0 , sizeof(sum)); for(i = 0 ; i < m ; i ++) Bin(P[i]); for(i = 0 ; i <= n ; i ++) printf("%d: %d\n",i,sum[i]); printf("\n"); } }
- poj 2318 poj 2398
- poj 2318
- POJ 2318
- poj 2318
- POJ 2318
- poj 2318
- poj.2318
- poj 2318
- poj 2318
- POJ-2318
- poj 2318
- POJ 2318
- POJ 2318 几何 POJ 2398
- POJ 2318 TOYS && POJ 2398 Toy Storage
- 【计算几何】POJ 2318 & POJ 2398
- POJ 2318 TOYS || POJ 2398 Toy Storage
- POJ 2318 TOYS
- poj 2318 TOYS
- useful opensource components & opensources apps
- Java中的10颗语法糖
- Oracle 11.2.0.3 ORA-12012 ORA-29280 ORA-06512 错误 解决方法
- git二分法查找命令的使用
- places training your code
- poj 2318
- MIUI Note 研究笔记之 读取raw资源
- UVA 10391 Compound Words
- FQDN
- select id,name,money,case money when 10000 then null else money-10000 end MONEY1
- 6个技术问题及解决方案
- Ubuntu10.04下配置和使用JDK-Mysql-Tomcat-SVN
- 图像分割之(一)概述
- wzplayer 近期将会支持BlackBerry和WinPhone8