Hdu 4458 Shoot the Airplane(判断点在多边形内)
来源:互联网 发布:手机计算器软件 编辑:程序博客网 时间:2024/04/30 15:20
题目地址:http://acm.hdu.edu.cn/showproblem.php?pid=4458
思路:以飞机为参考系,则飞机相对静止,子弹加上水平方向速度-v。则只需枚举时间,判断该时间时点(子弹)是否在多边形(飞机)内。注意g可以为0,分匀变速和匀速。另外本题精度要求较高,判断点在线段上用坐标差值,避免使用Dot 。
#include<cstdio>#include<cstring>#include<iostream>#include<algorithm>#define debuusing namespace std;const double eps = 1e-10;const int maxn=25;struct Point{ double x, y; Point(double x = 0, double y = 0) : x(x), y(y) {}};typedef Point Vector;int n,v,b,g;Point p[maxn];Vector operator - (const Point &A, const Point &B){ return Vector(A.x - B.x, A.y - B.y);}int dcmp(double x){ if(fabs(x) < eps) return 0; else return x < 0 ? -1 : 1;}double Dot(const Vector &A, const Vector &B){ return A.x * B.x + A.y * B.y;}double Cross(const Vector &A, const Vector B){ return A.x * B.y - A.y * B.x;}bool OnSegment(const Point &p, const Point &a1, const Point &a2){ //return dcmp(Cross(a1 - p, a2 - p)) == 0 && dcmp(Dot(a1 - p, a2 - p)) < 0; if(dcmp(Cross(a1-p,a2-p))) return 0; else if(dcmp(p.x-min(a1.x,a2.x))>=0&&dcmp(p.x-max(a1.x,a2.x))<=0&&dcmp(p.y-min(a1.y,a2.y))>=0&&dcmp(p.y-max(a1.y,a2.y))<=0) return 1; else return 0;}int isPointInPolygon(Point p, Point *poly, int n){ int wn = 0; for(int i = 0; i < n; ++i) { if(OnSegment(p, poly[i], poly[(i+1)%n])) return 0; int k=dcmp(Cross(poly[(i+1)%n]-poly[i], p-poly[i])); int d1=dcmp(poly[i].y-p.y); int d2=dcmp(poly[(i+1)%n].y-p.y); if(k>0&&d1<=0&&d2>0) wn++; if(k<0&&d2<=0&&d1>0) wn--; } if(wn!=0) return 1; else return 0;}int main(){#ifdef debug freopen("in.in","r",stdin);#endif // debug while(scanf("%d%d%d",&v,&b,&g)==3) { if(v==0&&b==0&&g==0) break; scanf("%d",&n); double maxy=0.0; for(int i=0; i<n; i++) { scanf("%lf%lf",&p[i].x,&p[i].y); maxy=max(maxy,p[i].y); } int flag=0; double Time=dcmp(g)?(2.0*b/g):(1.0*maxy/b); //cout<<Time<<endl; for(double i=0.0; i<=Time; i+=0.001) { Point tmp; tmp.x=-v*i,tmp.y=b*i-0.5*g*i*i; if(isPointInPolygon(tmp,p,n)) { printf("%.2f\n",i); flag=1; break; } } if(!flag) printf("Miss!\n"); } return 0;}
0 0
- Hdu 4458 Shoot the Airplane(判断点在多边形内)
- hdu 4458 Shoot the Airplane 点在平面内 相对运动
- HDU 4458 Shoot the Airplane(计算几何or数学)
- HDU 4458 Shoot the Airplane (2012年杭州赛区现场赛F题)
- HDU 4548 Shoot the Airplane 计算几何
- 判断点在多边形内
- 判断点在多边形内
- 判断点在多边形内
- 判断点在多边形内
- 多边形问题( 判断一个点在不在多边形内)
- HDU 1756 判断一个点是否在多边形内
- hdu 2823(旋转卡壳+线段相交判断+点在多边形内判断)
- poj 3182 The Grove (搜索+判断点在多边形内)
- [ACM] hdu Cupid's Arrow (判断点是否在多边形内)
- hdu 1756 Cubid's Arrow(判断点在多边形内)
- 判断点是否在任意多边形内(java)
- 判断点是否在多边形内(2D空间)
- 点在多边形内的判断(射线法)
- [88] Merge Sorted Array
- Unity 支持 IPV6 (IOS)
- POJ-2442-Sequence
- Codeforces Gym100531D Digits 暴力
- 郑轻OJ/ ZZULIOJ 1899 985的最大和难题(思维)
- Hdu 4458 Shoot the Airplane(判断点在多边形内)
- 一篇超容易让人理解的KMP算法文章
- Dubbo与Zookeeper、SpringMVC整合和使用(负载均衡、容错)
- void的使用
- hdu 5795 A Simple Nim(2016 Multi-University Training Contest 6——博弈)
- JAVA线程:概念与原理
- 详解JS运算符
- wamp开启memcache扩展
- 《流程的永恒之道:工作流及BPM技术的理论、规范、模式及最佳实践》书籍导读