It's a bird! It's a plane! It's coming right at us!
Although it sometimes seems like it, Superman can't fly (without a plane). Instead, he makes super-human leaps, especially over tall buildings. Since he never knows when he will need to catch a criminal, he can't register flight paths. To avoid hitting planes, he tries to keep his jumps as low to the ground as he can. Given a city-scape as input, find the angle and velocity of Superman's jump that minimizes his maximum altitude.
Recall that gravity provides an acceleration of 9.8 m/s2 downwards and the formula for Superman's vertical distance from his starting location is d(t)=v t + 0.5 a t2 where v is his initial velocity, a is his acceleration and tis time in seconds since the start of the leap.
Input:
Input consists of a sequence of city-scapes, each of the form
n
0 d1
h2 d2
:
h(n-1) d(n-1)
0 dn
Superman starts at ground level and leaps d1+...+dn metres, landing at ground level and clearing all of the buildings at heights h2 to h(n-1), each with the given widths. n will be at most 100.
Output:
Output is the angle and initial velocity that minimizes the height that Superman attains, both appearing on the same line. The values should be given to two decimal places and be accurate within 0.01 degrees or m/s, as appropriate.
Sample Input:
3 0 5 10 5 0 5 5 0 10.5 20 11.5 25 10 10 15 0 7
Diagram for Second City-scape
(Not to scale.)
Sample Output:
71.57 15.65 67.07 27.16
推公式!!!!
#include<stdio.h>
#include<math.h>
const double g=9.8;
const double PI=acos(-1.0);
struct Node
{
double x,y;
}node[210];
int main()
{
//freopen("test.in","r",stdin);
// freopen("test.out","w",stdout);
int n;
int t;
double w,hm;
double a,b;
while(scanf("%d",&n)!=EOF)
{
t=0;
double h;
double d;
scanf("%lf%lf",&h,&d);//第一行
w=d;
for(int i=1;i<n-1;i++)
{
scanf("%lf%lf",&node[t].y,&d);
node[t].x=w;
t++;
w+=d;
node[t].y=node[t-1].y;
node[t].x=w;
t++;
}
scanf("%lf%lf",&h,&d);
w+=d;
double tmp;
hm=0;
//printf("%lf\n",w);
for(int i=0;i<t;i++)
{
tmp=w*w*node[i].y/(-node[i].x*node[i].x+w*node[i].x)/4;
if(tmp>hm)hm=tmp;
}
double res1=atan(4*hm/w)*180/PI;
double res2=sqrt(g*w*w/(8*hm)+2*g*hm);
printf("%.2lf %.2lf\n",res1,res2);
}
return 0;
}