Poj2318
来源:互联网 发布:淘宝刀创 编辑:程序博客网 时间:2024/05/18 20:47
Poj2318
把一个箱子用不相交的n条直线划分成n+1个板块,标号0-n,洒落m个点,统计这些板块内点的个数
解:主要考察叉积的应用,用每个区间右边那条直线去代表区间,也就是说除了题目中的直线还应该加入一条解析式为x=MAX_RIGHT的直线,每加入一个点在线二分查找离这个点最近且在该点右侧的点。
#include<iostream>#include<cstdio>#include<cstdlib>#define eps 1e-10#define MAXM 5000using namespace std;struct point{double x,y;point(){x=y=0;}point(double _x,double _y){x=_x; y=_y;}};struct line{point s,e;}T[MAXM];//s为上层终结,e为下层终结. point V(point a,point b){return point(b.x-a.x,b.y-a.y);}double Cross(point a,point b){return (a.x*b.y-b.x*a.y);}bool left(int mid,point p){double a; point t;t=V(T[mid].s,p);//printf("%d %lf\n",mid,Cross(V(T[mid].s,T[mid].e),V(T[mid].s,p)));//system("pause");return (Cross(V(T[mid].s,T[mid].e),V(T[mid].s,p))<-eps);}int m,n,x1,y1,x2,y2; int area[MAXM];int main(){//freopen("poj.in","r",stdin);bool start=0;double a,b; int l,r,mid;while(1){memset(area,0,sizeof(area));if (start) printf("\n"); start=1;scanf("%d",&n);if (n==0) break;scanf("%d%d%d%d%d",&m,&x1,&y1,&x2,&y2);T[n+1].s.x=T[n+1].e.x=x2;T[n+1].s.y=y1; T[n+1].e.y=y2;for (int i=1;i<=n;i++){scanf("%lf%lf",&T[i].s.x,&T[i].e.x);T[i].s.y=y1; T[i].e.y=y2;}while(m--){scanf("%lf%lf",&a,&b);point p=point(a,b);l=1; r=n+1; bool flag;while (l<r){//printf("%d %d\n",l,r);mid=(l+r)>>1;if(left(mid,p)) r=mid;else l=mid+1;}area[l]++; }for(int i=1;i<=n+1;i++) printf("%d: %d\n",i-1,area[i]);}return 0;}
0 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
- poj 3262 Protecting the Flowers 【贪心】
- hdu 4634 Swipe Bo
- XBOOT核心组件之KOBJ技术详解
- 线段树扫描线uva11983
- 3.6.9 Using AUTO_INCREMENT
- Poj2318
- [LeetCode] Plus One
- 【数据结构_map容器迭代】Anagrams
- mahou 安装实例
- SRM556题解(T3除外)
- Linux驱动的platform机制
- Poj2653
- Codeforces Round #253 (Div. 1)D题
- 2014 MySql安装图解