HDU 4458 Shoot the Airplane (2012年杭州赛区现场赛F题)
来源:互联网 发布:json对象合并成一个 编辑:程序博客网 时间:2024/05/16 19:26
1.题目描述:点击打开链接
2.解题思路:本题利用运动的相对性解决。可以假设飞机固定不动,那么子弹相当于还有一个水平分量,只不过方向是-v。这样,问题就转化为一个动点什么时候到达一个多边形内部的问题了。不过本题有一个细节就是g可能等于0,因此要分匀变速运动和匀速运动2种情况求出最大可能的子弹飞行时间。另外一个细节就是本题对精度要求比较高,建议判断点是否在线段上改为利用坐标的差值来判断,避开使用Dot函数。
3.代码:
#include<iostream>#include<algorithm>#include<cassert>#include<string>#include<sstream>#include<set>#include<bitset>#include<vector>#include<stack>#include<map>#include<queue>#include<deque>#include<cstdlib>#include<cstdio>#include<cstring>#include<cmath>#include<ctime>#include<cctype>#include<functional>#pragma comment(linker, "/STACK:1024000000,1024000000")using namespace std;#define me(s) memset(s,0,sizeof(s))#define rep(i,n) for(int i=0;i<(n);i++)typedef long long ll;typedef unsigned int uint;typedef unsigned long long ull;//typedef pair <int, int> P;const double PI=acos(-1.0);const double eps=1e-10;int dcmp(double x){ if(fabs(x)<eps)return 0; return x<0?-1:1;}struct Point{ double x,y; Point(){} Point(double x,double y):x(x),y(y){} Point operator+(const Point&p){return Point(x+p.x,y+p.y);} Point operator-(const Point&p){return Point(x-p.x,y-p.y);} Point operator*(double p){return Point(x*p,y*p);} Point operator/(double p){return Point(x/p,y/p);}};typedef Point Vector;double Dot(Vector a,Vector b){return a.x*b.x+a.y*b.y;}double Cross(Vector a,Vector b){return a.x*b.y-a.y*b.x;}double Length(Vector a){return sqrt(Dot(a,a));}double Angle(Vector a,Vector b){return acos(Dot(a,b)/Length(a)/Length(b));}bool OnSegment(Point p,Point a,Point b){ if(dcmp(Cross(p-a,p-b)))return 0; return dcmp(a.x-p.x)*dcmp(b.x-p.x)<=0&&dcmp(a.y-p.y)*dcmp(b.y-p.y)<=0; //利用dcmp判断,避免使用Dot}typedef vector<Point> Polygon;int isPointInPolygon(Point p,Polygon poly){ int wn=0; int n=poly.size(); 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--; } return wn;}double v,b,g;int n;int main(){ while(~scanf("%lf%lf%lf",&v,&b,&g)) { if(v==0&&b==0&&g==0)break; scanf("%d",&n); Polygon p; double my=0.0,x,y; for(int i=0;i<n;i++) { scanf("%lf%lf",&x,&y); my=max(my,y); p.push_back(Point(x,y)); } int ok=0; double T=dcmp(g)?2.0*b/g:my/b; //分2种情况 for(double t=0.0;t<=T;t+=0.001) { Point tmp(-v*t,b*t-0.5*g*t*t); if(isPointInPolygon(tmp,p)) { printf("%.2lf\n",t); ok=1; break; } } if(!ok)puts("Miss!"); }}
0 0
- HDU 4458 Shoot the Airplane (2012年杭州赛区现场赛F题)
- HDU 4462 Scaring the Birds (2012年杭州赛区现场赛J题)
- HDU 4458 Shoot the Airplane(计算几何or数学)
- HDU 4455 Substrings (2012年杭州赛区现场赛C题)
- HDU 4453 Looploop (2012年杭州赛区现场赛A题)
- HDU 4454 杭州赛区现场赛B题
- Hdu 4458 Shoot the Airplane(判断点在多边形内)
- HDU 4548 Shoot the Airplane 计算几何
- HDU 4455 Substrings 第37届ACM/ICPC 杭州赛区现场赛 C题 (DP)
- hdu 4458 Shoot the Airplane 点在平面内 相对运动
- Substrings 第37届ACM/ICPC 杭州赛区现场赛C题(hdu 4455)
- HDU 4770 Lights Against Dudely -- 2013 杭州赛区现场赛-A(状态压缩)
- HDU 4422 The Little Girl who Picks Mushrooms (2012年长春赛区现场赛C题)
- HDU 4115 Eliminate the Conflict (2011年成都赛区现场赛E题)
- HDU 4435 charge-station (2012年天津赛区现场赛E题)
- HDU 5532 2015ACM-ICPC长春赛区现场赛F题
- 2016亚洲区域赛现场赛北京赛区f题
- 【杭州赛区现场赛PROBLEM I】阅读理解与模拟-The Power of Xiangqi
- Python 列表学习与使用
- Ubuntu 10.04 速配指南
- C语言基础知识之(十四):指针和字符数组、字符串数组
- Unity3D有限状态机(FSM)学习笔记【3】FSState类
- static详解
- HDU 4458 Shoot the Airplane (2012年杭州赛区现场赛F题)
- uva 11292 好长的英语题(简单的题目)
- android-屏幕适配(一)
- Linux进程间通信---有名管道 代码实现
- java并发编程第六章(3)使用阻塞式线程安全列表
- Codeforces Round #318(Div. 2) A
- CodeForces #318 (div1) C.Bear and Drawing
- ALTERA DE2 之 verilog HDL 学习笔记01 程序的并行
- Unity3D官方案例--SurvivalShooter游戏总结