?? noj 1051 行星位置.txt
字號(hào):
#include <iostream>
#include <stdio.h>
#include <algorithm>
#include <cmath>
using namespace std;
//行星位置 NOJ 1051
//兩直線交點(diǎn)坐標(biāo)求解,三角形外心坐標(biāo)求解,點(diǎn)旋轉(zhuǎn)坐標(biāo)求解,綜合幾何運(yùn)用
/*
輸入為:
第一行 行星繞恒星轉(zhuǎn)一圈的周期,衛(wèi)星從a點(diǎn)到b點(diǎn)的時(shí)間,從b點(diǎn)到c點(diǎn)的時(shí)間
第二行 a,b,c三點(diǎn)的坐標(biāo)
輸出為:
行星與恒星的距離
輸入:
360 90 90
5.0 1.0 0.0 6.0 -5.0 1.0
0 0 0
輸出:
5
*/
#define PI 3.1415926
typedef struct POINT
{
double x;
double y;
}POINT;
struct Beeline
{
double a;
double b;
double c;
};
POINT TwoBeeline(struct Beeline l1,struct Beeline l2)
{ //兩直線的交點(diǎn)
POINT p={0,0};
if(l1.a * l2.b == l1.b * l2.a) return p ; //兩直線平行
p.x = (l1.c * l2.b - l1.b * l2.c) / (l1.b * l2.a - l1.a * l2.b) ;
p.y = (l1.a * l2.c - l1.c * l2.a) / (l1.b * l2.a - l1.a * l2.b) ;
return p;
}
POINT Circumcenter(struct POINT P1,struct POINT P2,struct POINT P3)
{ //三角形的外心
struct Beeline l1,l2;
l1.a = P2.x - P1.x ;
l1.b = P2.y - P1.y ;
l1.c = (P1.y * P1.y - P2.y * P2.y + P1.x * P1.x - P2.x * P2.x) * 0.5000 ;
l2.a = P2.x - P3.x ;
l2.b = P2.y - P3.y ;
l2.c = (P3.y * P3.y - P2.y * P2.y + P3.x * P3.x - P2.x * P2.x) * 0.5000 ;
return TwoBeeline(l1,l2);
}
POINT rotate(POINT o,double alpha,POINT p)
{ //點(diǎn)p繞點(diǎn)o旋轉(zhuǎn)alpha角后的坐標(biāo)
POINT tp;
p.x-=o.x;
p.y-=o.y;
tp.x=p.x*cos(alpha)-p.y*sin(alpha)+o.x;
tp.y=p.y*cos(alpha)+p.x*sin(alpha)+o.y;
return tp;
}
int cal(POINT o,POINT a,POINT b,POINT c,double day1,double day2,double totle)
{
POINT AA,BB,WAIXIN;
double AJ,BJ;
double ans,tt;
//求得旋轉(zhuǎn)角度
AJ=(2*PI*(day1+day2))/totle;
BJ=(2*PI*day2)/totle;
//將點(diǎn)a,點(diǎn)b旋轉(zhuǎn)到與點(diǎn)c一起
//由于行星到衛(wèi)星的距離不變,可知這三個(gè)點(diǎn)所組成的三角形的外心,就是行星的坐標(biāo)
AA=rotate(o,AJ,a);
BB=rotate(o,BJ,b);
//求外心
WAIXIN=Circumcenter(AA,BB,c);
//求外心與原點(diǎn)的距離
ans=sqrt(pow((WAIXIN.x-o.x),2)+pow((WAIXIN.y-o.y),2));
tt=(int)(ans+0.5);
return tt;
}
int main()
{
POINT a,b,c,o;
double day1,day2,totleday;
o.x=0.0;o.y=0.0;
cin>>totleday>>day1>>day2;
while(!(totleday==0&&day1==0&&day2==0))
{
cin>>a.x>>a.y>>b.x>>b.y>>c.x>>c.y;
cout<<cal(o,a,b,c,day1,day2,totleday)<<endl;
cin>>totleday>>day1>>day2;
}
return 0;
}
?? 快捷鍵說明
復(fù)制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號(hào)
Ctrl + =
減小字號(hào)
Ctrl + -