送给圣诞夜的行程
spfa即可。。。
但是这个球面两点距离也太坑了吧。。。。
网上找的经纬度套进去不对,转化成坐标之后也还是又2个点WA。。。
心态完全爆炸。。。
1 #include<iostream> 2 #include<cmath> 3 #include<cstdio> 4 #include<cstdlib> 5 #include<string> 6 #include<cstring> 7 #define R 6374 8 #define PI 3.1415926 9 #define eps 1e-3 10 using namespace std; 11 struct poi{ 12 double x,y,z; 13 }a[10010]; 14 struct edge{ 15 int go,next; 16 double w; 17 }e[100010]; 18 int n,m,q[10000010]; 19 double d[10010]; 20 int head[10010],tot; 21 bool v[10010]; 22 void insert(int u,int v,double ww){ 23 e[++tot].go=v;e[tot].next=head[u];head[u]=tot;e[tot].w=ww; 24 } 25 double sqr(double x){ 26 return x*x; 27 } 28 double rad(double x){ 29 return x*PI/180; 30 } 31 double dabs(double a){ 32 if(a<0)return -a; 33 else return a; 34 } 35 double calc(int t1,int t2){ 36 double ans; 37 //ans=(double)R*acos(cos(t1.y)*cos(t2.y)*cos(t1.x-t2.x)+sin(t1.y)*sin(t2.y)); 38 ans=sqr(a[t1].x-a[t2].x)+sqr(a[t1].y-a[t2].y)+sqr(a[t1].z-a[t2].z); 39 return R*acos(1-ans/(2*sqr(R))); 40 } 41 void spfa(){ 42 for(int i=1;i<=n;i++)d[i]=99999999; 43 memset(v,0,sizeof(v)); 44 int l=0,r=1,x,y;q[1]=1;d[1]=0; 45 while(l!=r){ 46 x=q[++l];if(l==10000010)l=0;v[x]=0; 47 for(int i=head[x];i;i=e[i].next) 48 if(d[x]+e[i].w<d[y=e[i].go]){ 49 d[y]=d[x]+e[i].w; 50 if(!v[y]){v[y]=1;q[++r]=y;if(r==10000010)r=0;} 51 } 52 } 53 } 54 int main(){ 55 //freopen("input.txt","r",stdin); 56 //ios_base::sync_with_stdio(false); 57 //cin.tie(0); 58 cin>>n; 59 for(int i=1;i<=n;i++){ 60 int tmp1,tmp2; 61 cin>>tmp1; 62 char ch=getchar(); 63 if(ch=='W')tmp1*=-1; 64 cin>>tmp2; 65 ch=getchar(); 66 if(ch=='N')tmp2*=-1; 67 a[i].x=(double)R*sin(rad(tmp2)); 68 a[i].y=(double)R*cos(rad(tmp1))*cos(rad(tmp2)); 69 a[i].z=(double)R*cos(rad(tmp2))*sin(rad(tmp1)); 70 } 71 int uu,vv; 72 while(cin>>uu>>vv){ 73 double tmp=calc(uu,vv); 74 //cout<<tmp<<endl; 75 insert(uu,vv,tmp); 76 } 77 spfa(); 78 if(dabs(d[n]-99999999)<eps)cout<<"Impossible"; 79 else printf("%.2f",d[n]); 80 return 0; 81 }