hdu4458Shoot the Airplane+计算几何
2016-08-23 21:15
316 查看
Problem Description
XXX is playing an interesting game which is based on a 2D plane. In this game, he is required to shoot an airplane. The airplane flies horizontally. The shape of it can be regarded as a simple polygon. Player has to shoot at point (0, 0) upward vertically. Because the bullet is very small, it can be regarded as a point. The airplane is hit only if the bullet goes into the airplane. The airplane is not hit if the bullet only touches the edge of the airplane. The gravity should be considered. The acceleration of gravity is g and its direction is downward vertically. So the speed of the bullet may be change during flying. But the speed of airplane is constant because it has engines. XXX wants to know the time it takes the bullet to hit the airplane after shooting.
Input
There are multiple cases.
In each case, there are three integers v (-10<= v <= 10), b (1 <= b <= 10), g (0 <= g <= 10) in the first line. v denotes the speed of airplane. The flying direction is from left to right if v is positive and the direction is from right to left if v is negative. b denotes the initial speed of bullet. g is the acceleration of gravity. Then the input will describe the position of the airplane when XXX shoots. In the second line, there is one integer n (3 <= n <= 20) which represents the number of vertexes of the airplane (polygon). In each of the next n lines, there are two integers x (-100 <= x <= 100), y (0 < y<= 100) which give the position of a vertex in order. There is a blank line after each case. The input ends with 0 0 0.
Output
If the airplane is hit, then output the time it takes the bullet to hit it after shooting in one line. The answer should be rounded to 2 digits after decimal point. If the airplane is not hit, then output “Miss!” in one line.
Sample Input
-10 10 2
9
6 9
10 9
10 16
25 16
25 20
10 20
10 27
6 27
-10 18
-10 10 2
9
6 9
10 9
10 16
20 16
20 20
10 20
10 27
6 27
-10 18
0 0 0
Sample Output
2.00
Miss!
Source
2012 Asia Hangzhou Regional Contest
题意:多边形的飞机水平飞行。从原点有炮弹垂直向上打出,问能不能打到飞机。
解法:可以将飞机看作静止的,相对于炮弹是抛物线的飞行,直接枚举时间,计算出炮弹的坐标,然后判断点是否在多边形内。。。(做的时候g==0从脑海中一闪而过。然后T死了。。)当g为0的时候,就是匀速直线运动,最大时间就是飞过最高点的时间。。
XXX is playing an interesting game which is based on a 2D plane. In this game, he is required to shoot an airplane. The airplane flies horizontally. The shape of it can be regarded as a simple polygon. Player has to shoot at point (0, 0) upward vertically. Because the bullet is very small, it can be regarded as a point. The airplane is hit only if the bullet goes into the airplane. The airplane is not hit if the bullet only touches the edge of the airplane. The gravity should be considered. The acceleration of gravity is g and its direction is downward vertically. So the speed of the bullet may be change during flying. But the speed of airplane is constant because it has engines. XXX wants to know the time it takes the bullet to hit the airplane after shooting.
Input
There are multiple cases.
In each case, there are three integers v (-10<= v <= 10), b (1 <= b <= 10), g (0 <= g <= 10) in the first line. v denotes the speed of airplane. The flying direction is from left to right if v is positive and the direction is from right to left if v is negative. b denotes the initial speed of bullet. g is the acceleration of gravity. Then the input will describe the position of the airplane when XXX shoots. In the second line, there is one integer n (3 <= n <= 20) which represents the number of vertexes of the airplane (polygon). In each of the next n lines, there are two integers x (-100 <= x <= 100), y (0 < y<= 100) which give the position of a vertex in order. There is a blank line after each case. The input ends with 0 0 0.
Output
If the airplane is hit, then output the time it takes the bullet to hit it after shooting in one line. The answer should be rounded to 2 digits after decimal point. If the airplane is not hit, then output “Miss!” in one line.
Sample Input
-10 10 2
9
6 9
10 9
10 16
25 16
25 20
10 20
10 27
6 27
-10 18
-10 10 2
9
6 9
10 9
10 16
20 16
20 20
10 20
10 27
6 27
-10 18
0 0 0
Sample Output
2.00
Miss!
Source
2012 Asia Hangzhou Regional Contest
题意:多边形的飞机水平飞行。从原点有炮弹垂直向上打出,问能不能打到飞机。
解法:可以将飞机看作静止的,相对于炮弹是抛物线的飞行,直接枚举时间,计算出炮弹的坐标,然后判断点是否在多边形内。。。(做的时候g==0从脑海中一闪而过。然后T死了。。)当g为0的时候,就是匀速直线运动,最大时间就是飞过最高点的时间。。
#include<bits/stdc++.h> using namespace std; const int maxn=100; const double eps=1e-8; struct point{ double x,y; point(){}; point (double x,double y):x(x),y(y){}; friend point operator - (const point &a,const point &b){ return point(a.x-b.x,a.y-b.y); } }; int dcmp(double k){ return k<-eps?-1:k>eps?1:0; } double det(const point &a,const point &b){ return a.x*b.y-a.y*b.x; } double dot(const point &a,const point &b){ return a.x*b.x+a.y*b.y; } bool PointOnSegment(point p,point s,point t){ return dcmp(det(p-s,t-s))==0&&dcmp(dot(p-s,p-t))<=0; } struct Polygon{ int n; point a[maxn]; Polygon(){}; int Point_in(point t){ int num=0; a =a[0]; for(int i=0;i<n;i++){ if(PointOnSegment(t,a[i],a[i+1])) return 2; int k=dcmp(det(a[i+1]-a[i],t-a[i])); int d1=dcmp(a[i].y-t.y); int d2=dcmp(a[i+1].y-t.y); if(k>0&&d1<=0&&d2>0) num++; if(k<0&&d2<=0&&d1>0) num--; } return num!=0; } }; Polygon plane; int main(void) { int v,b,g; while(scanf("%d %d %d",&v,&b,&g)!=EOF){ if(v==0&&b==0&&g==0) break; scanf("%d",&plane.n); double tem=0; for(int i=0;i<plane.n;i++){ scanf("%lf %lf",&plane.a[i].x,&plane.a[i].y); //if(plane.a[i].y<d.y) d=point(plane.a[i].x,plane.a[i].y); tem=max(tem,plane.a[i].y); } double maxt; if(g<eps) maxt=tem/b;//大概就可以认为是0了 else maxt=2.0*b/g; bool flag=false; double t; for( t=0.0;t<=maxt;t+=0.001){ point op; op.x=-v*t; op.y=b*t-g*t*t/2.0; if(plane.Point_in(op)==1){ flag=true; break; } } if(flag) printf("%.2f\n",t); else printf("Miss!\n"); } return 0; }
相关文章推荐
- 计算几何--POJ--1654--Area
- 计算几何题目
- uva 12304 2D Geometry 110 in 1! 计算几何
- POJ1265 Area (Pick定理,多边形面积,计算几何)
- 【计算几何】【simpson自适应公式】【NOI2004】降雨量
- zoj 1041 计算几何 叉积运用
- Codeforces 32E Hide-and-Seek 求2点关于镜面反射 计算几何
- 3维计算几何模板
- 盲僧和他的计算几何
- HDU 6055 Regular polygon (计算几何 + 国家队论文结论)
- 【Computing Geometry --计算几何】初级篇 <一>
- poj2398+poj2318(计算几何+二分)
- HYSBZ/BZOJ 1038 [ZJOI2008] 瞭望塔 - 计算几何
- Codeforces Round #358 (Div. 2) E 计算几何 旋转卡壳求最大三角形面积
- [caioj]【计算几何】面积 计算几何 叉积
- ACM计算几何题目推荐
- Codeforces Gym 100286A. Aerodynamics 计算几何 求二维凸包面积
- *HDU 1392 计算几何
- *HDU 1007 计算几何
- 开源几何计算数学库