记录编号 118988 评测结果 AAAAAAAAAA
题目名称 [POJ2852]模型火箭的飞行高度 最终得分 100
用户昵称 Gravatarcstdio 是否通过 通过
代码语言 C++ 运行时间 0.020 s
提交时间 2014-09-10 15:06:58 内存使用 0.32 MiB
显示代码纯文本
#include<iostream>
#include<cstdio>
#include<algorithm>
#include<cstring>
#include<cmath>
using namespace std;
#define sqr(x) (x)*(x)
const double pi=acos(-1.0);
double turn_rad(double x){
	return x/180.0*pi;
}
class POINT{//三维点或向量
public:
	double x,y,z;
};
POINT MP(double x,double y,double z){
	POINT ans;
	ans.x=x,ans.y=y,ans.z=z;
	return ans;
}
void print(POINT p){cout<<"("<<p.x*50<<","<<p.y*50<<","<<p.z*50<<")";}
POINT operator + (POINT a,POINT b){return MP(a.x+b.x,a.y+b.y,a.z+b.z);}
POINT operator - (POINT a,POINT b){return MP(a.x-b.x,a.y-b.y,a.z-b.z);}
POINT operator * (POINT a,double t){return MP(a.x*t,a.y*t,a.z*t);}
double module(POINT a){return sqrt(sqr(a.x)+sqr(a.y)+sqr(a.z));}
double azimuth_deg(POINT a){//方位角
	double alpha=atan2(a.y,a.x);
	if(alpha<0) alpha+=2*pi;
	return alpha/pi*180.0;
}
double elevation_deg(POINT a){//仰角
	double alpha=atan2(a.z,sqrt(sqr(a.x)+sqr(a.y)));
	if(alpha<0) alpha+=2*pi;
	return alpha/pi*180.0;
}
//叉积,运算结果是两个向量的某一公垂向量
POINT crp(POINT a,POINT b){return MP(a.y*b.z-a.z*b.y,a.z*b.x-a.x*b.z,a.x*b.y-a.y*b.x);}
double dot(POINT a,POINT b){return a.x*b.x+a.y*b.y+a.z*b.z;}
int N;
double HA,HB;
//前二者是仰角,后二者是方位角
double alpha,beta,gamm,delta;
/*以AB中点O为原点,OB为x+轴,O朝火箭发射点为y+轴,O朝上为z+轴
假设公垂线和A视线交于D,和B视线交于E,公垂线段中点为C
*/
POINT a,b,n;//向量,a和AD同向,b和BD同向,n垂直于a,b
POINT A,B;
POINT AB;
void work(void){
	a=MP(1.0,tan(gamm),tan(alpha)/cos(gamm));
	b=MP(-1.0,-tan(delta),tan(beta)/cos(pi-delta));
	n=crp(a,b);
	//n大略指向下
	/*下面均为向量运算:
	AB=AD+DE-EB
	AB dot n = DE dot n = |DE|*|n|
	DE=|DE|/|n| * n=(AB dot n / n dot n) * n
	*/
	POINT DE=n*(dot(AB,n)/dot(n,n));
	POINT AB1=AB-DE;
	POINT PB1=b*(dot(AB1,b)/dot(b,b));
	POINT AP=AB1-PB1;
	POINT AD=a*(dot(AP,AP)/dot(a,AP));
	POINT C=A+AD+DE*0.5;
	printf("%.0lf\n",C.z*50.0);
}
int main(){
	freopen("modelrocketheight.in","r",stdin);
	freopen("modelrocketheight.out","w",stdout);
	//先将50英尺视作一个单位,在最后乘回去
	scanf("%d",&N);
	scanf("%lf%lf",&HA,&HB);
	HA/=50.0,HB/=50.0;
	A=MP(-1.0,0.0,HA),B=MP(1.0,0.0,HB);
	AB=B-A;
	for(int i=1;i<=N;i++){
		scanf("%lf%lf%lf%lf",&alpha,&beta,&gamm,&delta);
		alpha=turn_rad(alpha),beta=turn_rad(beta),gamm=turn_rad(gamm),delta=turn_rad(delta);
		printf("%d: ",i);
		work();
	}
	return 0;
}