POJ 2318 TOYS
来源:互联网 发布:微信连wifi 固件源码 编辑:程序博客网 时间:2024/04/29 15:35
#include<iostream>#include<cstdio>#include<cstring>#include<algorithm>#include<cmath>using namespace std;#define FOR(i,a,b) for(int (i)=(a);(i)<=(b);(i)++)#define DOR(i,a,b) for(int (i)=(a);(i)>=(b);(i)--)#define oo 1<<30#define eps 1e-6#define nMax 6010int dcmp(double x){ if(fabs(x)<=eps) return 0; else return x > 0?1:-1;}struct Point{ double x,y; Point (double x=0,double y=0) : x(x),y(y) {} Point friend operator - (Point const& p1,Point const& p2){ return Point(p2.x-p1.x,p2.y-p1.y); } double friend operator * (Point const& p1,Point const& p2){ return p1.x*p2.y - p1.y*p2.x; } void read() { scanf("%lf%lf",&x,&y); } void make(double _x,double _y) {x=_x;y=_y;}};struct Segment { Point p1,p2;};typedef Segment Seg;int InSide(Seg s1,Seg s2,Point p){ if(dcmp(p.y-s1.p1.y)>0 || dcmp(p.y-s1.p2.y)<0 ) return 0; if(dcmp((s1.p2-p)*(p-s1.p1))>=0 && dcmp((s2.p2-p)*(p-s2.p1))<=0) return 1; return 0;}int n,m;Seg s[nMax];Point p[nMax];double ui,li;int ans[nMax];int first = 1;int Bserch(Point p){ int l=0,r=n; int ans = 0; while(l<=r){ int mid = (l+r)>>1; if(dcmp((s[mid].p2-p)*(p-s[mid].p1)) >= 0) ans = mid,l = mid+1; else r = mid-1; } return ans;}int main(){#ifndef ONLINE_JUDGEfreopen("input.txt","r",stdin);//freopen("output.txt","w",stdout);#endif while(~scanf("%d",&n),n){ if(first) first = 0; else puts(""); scanf("%d",&m); s[0].p1.read();s[n+1].p2.read(); s[0].p2.make(s[0].p1.x,s[n+1].p2.y); s[n+1].p1.make(s[n+1].p2.x,s[0].p1.y); for(int i=1;i<=n;i++) { scanf("%lf%lf",&ui,&li); s[i].p1.make(ui,s[0].p1.y); s[i].p2.make(li,s[0].p2.y); } for(int i=1;i<=m;i++) p[i].read(); memset(ans,0,sizeof(ans)); for(int i=1;i<=m;i++) { ans[Bserch(p[i])]++; } for(int i=0;i<=n;i++) printf("%d: %d\n",i,ans[i]); } return 0;}
仅为纪念貌似第一道计算几何,虽然好像不是特别难。。。
纯暴力的手段是行不通的,对于每个点我们二分查找它所在的空间。。
- POJ 2318 TOYS
- poj 2318 TOYS
- poj 2318 TOYS
- poj 2318 TOYS
- POJ 2318 TOYS
- poj 2318 TOYS
- POJ 2318 TOYS
- POJ 2318 TOYS
- POJ 2318 TOYS
- poj 2318 TOYS
- poj - 2318 - TOYS
- poj 2318 TOYS
- POJ 2318 TOYS
- poj 2318 TOYS
- poj 2318 TOYS
- POJ 2318 TOYS
- poj 2318 Toys
- POJ 2318 TOYS
- 【diannaoxitong】如何在没有路由器的情况下组建局域网
- HDU 1874题畅通工程续(数据很坑)
- Matlab实现HSI与RGB转换
- MySQL常用时间函数
- Uncompressing Linux..... done, booting the kernel.
- POJ 2318 TOYS
- 软件的本质
- 大量插入:使用SQL*Loader Direct Path选项
- 关于垃圾回收
- Eclipse中servlet显示无法导入javax.servlet包问题的解决方案Eclipse中servlet显示无法导入javax.servlet包问题的解决方案
- Android之Service与IntentService的比较
- Oracle EM 11g/12c资料库 迁移操作
- d is undefined错误
- svn学习网址