【题目链接】:click here~~
【题目大意】:
Description
小白最近被空军特招为飞行员,参与一项实战演习。演习的内容是轰炸某个岛屿。。。
作为一名优秀的飞行员,任务是必须要完成的,当然,凭借小白出色的操作,顺利地将炸弹投到了岛上某个位置,可是长官更关心的是,小白投掷的炸弹到底摧毁了岛上多大的区域?
岛是一个不规则的多边形,而炸弹的爆炸半径为R。
小白只知道自己在(x,y,h)的空间坐标处以(x1,y1,0)的速度水平飞行时投下的炸弹,请你计算出小白所摧毁的岛屿的面积有多大. 重力加速度G = 10.
作为一名优秀的飞行员,任务是必须要完成的,当然,凭借小白出色的操作,顺利地将炸弹投到了岛上某个位置,可是长官更关心的是,小白投掷的炸弹到底摧毁了岛上多大的区域?
岛是一个不规则的多边形,而炸弹的爆炸半径为R。
小白只知道自己在(x,y,h)的空间坐标处以(x1,y1,0)的速度水平飞行时投下的炸弹,请你计算出小白所摧毁的岛屿的面积有多大. 重力加速度G = 10.
Input
首先输入三个数代表小白投弹的坐标(x,y,h);
然后输入两个数代表飞机当前的速度(x1, y1);
接着输入炸弹的爆炸半径R;
再输入一个数n,代表岛屿由n个点组成;
最后输入n行,每行输入一个(x',y')坐标,代表岛屿的顶点(按顺势针或者逆时针给出)。(3<= n < 100000)
然后输入两个数代表飞机当前的速度(x1, y1);
接着输入炸弹的爆炸半径R;
再输入一个数n,代表岛屿由n个点组成;
最后输入n行,每行输入一个(x',y')坐标,代表岛屿的顶点(按顺势针或者逆时针给出)。(3<= n < 100000)
Output
输出一个两位小数,表示实际轰炸到的岛屿的面积。
Sample Input
0 0 2000 100 0 100 4 1900 100 2000 100 2000 -100 1900 -100
Sample Output
15707.96
Source
2009 Multi-University Training Contest 10 - Host by NIT
【思路】:如果忘了抛物线的一些公式,建议上百度复习一下,这里我们假设最后投掷点圆心坐标为(ceter_x0,ceter_y0),空间坐标(x,y,H),初始速度(x1,y1,0)那么由高度为H,最后投掷点到地面竖直速度为0,由公式得:起点速度为:V^2=2*g*H,得 V=sqrt(2*g*H),那么时间t为V/g=sqrt(2*g*H)/g,注意这里是空间坐标,那么最后ceter_x0=x+t*x1,ceter_y0=y+t*y1。
由此,套入模板求出面积。
代码:
/*
* 多边形和圆面积并
* Problem: HDU No.2892
* Running time: 62MS
* Complier: G++
* Author: javaherongwei
* Create Time: 15:34 2015/10/1 星期四
*/
#include <math.h>
#include <stdio.h>
#include <string.h>
#include <iostream>
#include <algorithm>
using namespace std;
const double pi=acos(-1.0);
const double e=exp(1.0);
const double eps=1e-8;
const int maxn=100005;
double R,k;
int n,m;
struct point // 点或向量结构
{
double x,y;
point(double _x=0.0,double _y=0.0):x(_x),y(_y) {}
point operator - (const point &p)
{
return point(x-p.x,y-p.y);
}
double sqrx() //向量的模
{
return sqrt(x*x+y*y);
}
} area[maxn];
int dcmp(double x)
{
return (x>eps)-(x<-eps);
}
double xmult(point &p1,point &p2,point &p0)//叉积
{
return (p1.x-p0.x)*(p2.y-p0.y)-(p1.y-p0.y)*(p2.x-p0.x);
}
double distancex(point &p1,point &p2)
{
return sqrt((p1.x-p2.x)*(p1.x-p2.x)+(p1.y-p2.y)*(p1.y-p2.y));
}
point intersection(point u1,point u2,point v1,point v2) //两直线交点
{
point ret = u1;
double t = ((u1.x-v1.x)*(v1.y-v2.y)-(u1.y-v1.y)*(v1.x-v2.x))/((u1.x-u2.x)*(v1.y-v2.y)-(u1.y-u2.y)*(v1.x-v2.x));
ret.x += (u2.x-u1.x)*t;
ret.y += (u2.y-u1.y)*t;
return ret;
}
void intersection_line_circle(point c, double r, point l1, point l2, point & p1, point & p2) //直线与圆相交
{
point p = c;
double t;
p.x += l1.y-l2.y;
p.y += l2.x-l1.x;
p = intersection(p, c, l1, l2);
t = sqrt(r*r-distancex(p, c)*distancex(p, c))/distancex(l1, l2);
p1.x = p.x+(l2.x-l1.x)*t;
p1.y = p.y+(l2.y-l1.y)*t;
p2.x = p.x-(l2.x-l1.x)*t;
p2.y = p.y-(l2.y-l1.y)*t;
}
point len_pot_seg(point p, point l1, point l2)//点到线段的最近距离
{
point t = p;
t.x += l1.y-l2.y;
t.y += l2.x-l1.x;
if (xmult(l1, t, p)*xmult(l2, t, p)>eps)
return distancex(p, l1)<distancex(p, l2) ? l1 : l2;
return intersection(p, t, l1, l2);
}
double distp(point & a, point & b)
{
return (a.x-b.x)*(a.x-b.x)+(a.y-b.y)*(a.y-b.y);
}
double Direct_Triangle_Circle_Area(point a, point b, point o, double r)
{
double sign = 1.0;
a = a-o;
b = b-o;
o = point(0.0, 0.0);
if(fabs(xmult(a, b, o)) < eps) return 0.0;
if(distp(a, o) > distp(b, o))
{
swap(a, b);
sign = -1.0;
}
if (distp(a, o) < r*r+eps)
{
if (distp(b, o) < r*r+eps) return xmult(a, b, o)/2.0*sign;
point p1, p2;
intersection_line_circle(o, r, a, b, p1, p2);
if (distancex(p1, b) > distancex(p2, b)) swap(p1, p2);
double ret1 = fabs(xmult(a, p1, o));
double ret2 = acos((p1.x*b.x+p1.y*b.y)/p1.sqrx()/b.sqrx())*r*r;
double ret = (ret1+ret2)/2.0;
if (xmult(a, b, o)<eps && sign>0.0 || xmult(a, b, o)>eps && sign<0.0) ret = -ret;
return ret;
}
point ins = len_pot_seg(o, a, b);
if(distp(o, ins)>r*r-eps)
{
double ret = acos((a.x*b.x+a.y*b.y)/a.sqrx()/b.sqrx())*r*r/2.0;
if(xmult(a, b, o)<eps && sign>0.0 || xmult(a, b, o)>eps && sign<0.0) ret = -ret;
return ret;
}
point p1, p2;
intersection_line_circle(o, r, a, b, p1, p2);
double cm = r/(distancex(o, a)-r);
point m = point((o.x+cm*a.x)/(1+cm),(o.y+cm*a.y)/(1+cm));
double cn = r/(distancex(o, b)-r);
point n = point((o.x+cn*b.x)/(1+cn),(o.y+cn*b.y)/(1+cn));
double ret1 = acos((m.x*n.x+m.y*n.y)/m.sqrx()/n.sqrx())*r*r;
double ret2 = acos((p1.x*p2.x+p1.y*p2.y)/p1.sqrx()/p2.sqrx())*r*r-fabs(xmult(p1, p2, o));
double ret = (ret1-ret2)/2.0;
if(xmult(a, b, o)<eps && sign>0.0||xmult(a, b, o)>eps && sign<0.0) ret=-ret;
return ret;
}
int main()
{
int tot=1;
double x,y,H;
double x1,y1,R;
while(cin>>x>>y>>H)
{
cin>>x1>>y1;
cin>>R;
cin>>n;
for(int i=0; i<n; i++) scanf("%lf%lf", &area[i].x, &area[i].y);
double V=sqrt(2*10*H);
double t=V/10;
double ceter_x0=x+x1*t;
double ceter_y0=y+y1*t;
point ceter_xy=point(ceter_x0,ceter_y0);
double sum=0.0;
for(int i=0; i<n-1; i++) sum += Direct_Triangle_Circle_Area(area[i], area[i+1], ceter_xy, R);
sum += Direct_Triangle_Circle_Area(area[n-1], area[0], ceter_xy, R);
printf("%.2f\n",fabs(sum));
} return 0;
}