Posted on 2006-09-10 01:38
魔のkyo 阅读(340)
评论(0) 编辑 收藏 引用 所属分类:
Programming
//这题我试sample output的时候精度不够,差了0.01,修改了好多细节还是差0.01,试着提交居然一下就过了
//算法还有一些不足,paowuxian workout(point a,point b)中没有判断是否和(0,0)三点共线的问题
//但是if(Vec[i]>pwx)可以避免掉a是x轴上的点(注释1处)
#include <iostream>
#include <vector>
#include <cmath>
#include <stdlib.h>
#define PI 3.141592653589793238
using namespace std;
//过原点的抛物线y=ax^2+bx
class paowuxian{
public:
double a;
double b;
};
class point{
public:
double x;
double y;
};
//返回过原点,点a,点b,的抛物线
//前提条件:三点不共线
paowuxian workout(point a,point b)
{
paowuxian res;
double a11,a12,a21,a22,b1,b2;
a11=a.x*a.x;
a12=a.x;
a21=b.x*b.x;
a22=b.x;
b1=a.y;
b2=b.y;
res.a=(b1*a22-b2*a12)/(a11*a22-a21*a12);
res.b=(a11*b2-a21*b1)/(a11*a22-a21*a12);
return res;
}
//点p_a在抛物线pwx上方时返回真
bool operator > (point p_a,paowuxian pwx)
{
return (p_a.y > (pwx.a*p_a.x+pwx.b)*p_a.x);
}
int main()
{
int n;
vector<point> Vec;
while(scanf("%d",&n)!=EOF){
point point_tmp;
point_tmp.x=point_tmp.y=0.0;
paowuxian pwx;
Vec.clear();
//把点压入动态数组
for(int i=0;i<n;++i){
double y,dx;
scanf("%lf %lf",&y,&dx);
point_tmp.y=y;
Vec.push_back(point_tmp);//这里会取到一些显然不必要的点,有待改进
point_tmp.x+=dx;
Vec.push_back(point_tmp);
}
//为抛物线赋初值
//pwx=workout(Vec.front(),Vec.back());
pwx=workout(Vec[1],Vec.back());//目前Vec[0]是x轴上的点不能取,改进后需修改
//如果有点在当前抛物线上方,则重新计算抛物线,最终包含所有点在下方
for(int i=1;i<Vec.size()-1;i++){
if(Vec[i]>pwx){//注释1
pwx=workout(Vec[i],Vec.back());
}
}
//printf("%lf,%lf\n",pwx.a,pwx.b);
point highest;//抛物线顶点
highest.x=Vec.back().x/2;
highest.y=highest.x*(highest.x*pwx.a+pwx.b);
double angle_r,angle_d;//仰角的弧度表示和角度表示
angle_r=atan(highest.y*2/highest.x);
angle_d=angle_r*180/PI;
//printf("%.2lf\n",angle);
double vx,vy,velocity;
vy=sqrt(2.0*9.8*highest.y);
velocity=vy/sin(angle_r);
printf("%.2lf %.2lf\n",angle_d,velocity);
}
return 0;
}