[POJ2398]Toy Storage(计算几何+二分)
来源:互联网 发布:前端程序员是干什么的 编辑:程序博客网 时间:2024/04/18 21:07
题目描述
传送门
题解
同POJ2318
代码
#include<algorithm>#include<iostream>#include<cstring>#include<cstdio>#include<ctime>using namespace std;#define N 10005const double eps=1e-9;int dcmp(double x){ if (x<=eps&&x>=-eps) return 0; return (x>0)?1:-1;}struct Vector{ double x,y; Vector(double X=0,double Y=0) { x=X,y=Y; }};typedef Vector Point;struct Line{ Point p; Vector v; Line(Point P=Point(0,0),Vector V=Vector(0,0)) { p=P,v=V; } bool operator < (Line A) const { return p.x<A.p.x; }};Vector operator - (Vector A,Vector B) {return Vector(A.x-B.x,A.y-B.y);}int n,m;double a,b,c,d,ui,li,x,y;Line l[N];int cnt[N],ans[N];void clear(){ memset(cnt,0,sizeof(cnt)); memset(ans,0,sizeof(ans));}int cmp(Line a,Line b){ return a<b;}double Cross(Vector A,Vector B){ return A.x*B.y-A.y*B.x;}bool check(int mid,Point pt){ Point st=l[mid].p; Vector c=Vector(pt.x-st.x,pt.y-st.y); double t=Cross(l[mid].v,c); if (dcmp(t)>0) return true; else return false;}int find(Point pt){ int l=1,r=n+1,mid,ans=0; while (l<=r) { mid=(l+r)>>1; if (check(mid,pt)) ans=mid,r=mid-1; else l=mid+1; } return ans;}int main(){ while (~scanf("%d",&n)) { if (!n) break; puts("Box"); clear(); scanf("%d",&m); scanf("%lf%lf%lf%lf",&a,&b,&c,&d); for (int i=1;i<=n;++i) { scanf("%lf%lf",&ui,&li); l[i]=Line(Point(li,d),Vector(ui-li,b-d)); } l[n+1]=Line(Point(c,d),Vector(0,b-d)); sort(l+1,l+n+2); for (int i=1;i<=m;++i) { scanf("%lf%lf",&x,&y); int loc=find(Point(x,y)); ++cnt[loc]; } for (int i=1;i<=n+1;++i) ++ans[cnt[i]]; for (int i=1;i<=m;++i) if (ans[i]) printf("%d: %d\n",i,ans[i]); }}
0 0
- [POJ2398]Toy Storage(计算几何+二分)
- 【计算几何】 poj2398 Toy Storage
- poj2398——Toy Storage(计算几何)
- ACM-计算几何之Toy Storage——poj2398
- ACM-计算几何之Toy Storage——poj2398
- poj 2398 Toy Storage 计算几何+二分
- Toy Storage(poj2398,向量叉乘+二分查找)
- poj2398+poj2318(计算几何+二分)
- poj 2398 Toy Storage(计算几何)
- Toy Storage(二维计算几何基础)
- 【POJ 2398】Toy Storage(计算几何)
- poj 2398 Toy Storage (计算几何)
- poj2398 - Toy Storage
- [Poj2398]Toy Storage
- POJ2398-Toy Storage
- poj2398 Toy Storage
- POJ2318 TOYS 和POJ2398 Toy Storage题解(点在四边形内)(简单几何)
- POJ2398 计算几何外积+二分
- 一个字总结我的2016
- java 上机实践四 类与对象
- [POJ2318]TOYS(计算几何+二分)
- ZXing 源码分析(简阅)
- 备忘录
- [POJ2398]Toy Storage(计算几何+二分)
- 查看android studio和apk文件签名
- 输入年月 返回当前月份的天数
- 60. Permutation Sequence
- 前端工程师面试指南
- win10 64位免安装版mysql-5.7.16-winx64安装步骤
- Host 'XXX' is not allowed to connect to this MySQL server 解决方案
- HDU 5739(点双连通)
- UIP协议栈UDP数据发送的问题