标签:ecs mes for href ase ble max size out
注意精度,不要用long long 输出,用%.0f输出
AC_Code
1 #include <iostream> 2 #include <cstdio> 3 #include <string> 4 #include <cstring> 5 #include <string> 6 #include <cmath> 7 #include <cstdlib> 8 #include <algorithm> 9 #include <bits/stdc++.h> 10 using namespace std; 11 typedef long long ll; 12 const int maxn = 65; 13 const int inf=0x3f3f3f3f; 14 const ll mod=1e9+7; 15 16 map<string,int>mp; 17 int n,w,q; 18 struct node{ 19 ll xi,yi,zi; 20 // string s; 21 }a[maxn]; 22 double f[maxn][maxn]; 23 double h[maxn]; 24 string s1[maxn], s2[maxn]; 25 26 void floyd(){ 27 for(int k=0;k<n;k++){ 28 for(int i=0;i<n;i++){ 29 for(int j=0;j<n;j++){ 30 if( f[i][j]>f[i][k]+f[k][j]){ 31 f[i][j]=f[i][k]+f[k][j]; 32 } 33 } 34 } 35 } 36 } 37 38 void init(){ 39 for(int i=0;i<n;i++){ 40 for(int j=i+1;j<n;j++){ 41 ll x=abs(a[i].xi-a[j].xi); 42 ll y=abs(a[i].yi-a[j].yi); 43 ll z=abs(a[i].zi-a[j].zi); 44 f[i][j]=(double)sqrt(1.0*x*x+1.0*y*y+1.0*z*z); 45 f[j][i]=f[i][j]; 46 } 47 } 48 } 49 50 int main() 51 { 52 int t,cas=0; 53 scanf("%d",&t); 54 while( t-- ){ 55 string ss,sss; 56 memset(a,0,sizeof(a)); 57 scanf("%d",&n); 58 for(int i=0;i<n;i++){ 59 ll x,y,z; 60 cin>>ss>>x>>y>>z; 61 mp[ss]=i; 62 // a.s = ss; 63 a[i].xi = x; 64 a[i].yi = y; 65 a[i].zi = z; 66 } 67 init(); 68 scanf("%d",&w); 69 for(int i=0;i<w;i++){ 70 cin>>ss>>sss; 71 int u=mp[ss]; 72 int v=mp[sss]; 73 f[u][v]=0.0; 74 } 75 floyd(); 76 scanf("%d",&q); 77 for(int i=0;i<q;i++){ 78 cin>>s1[i]>>s2[i]; 79 int u=mp[s1[i]]; 80 int v=mp[s2[i]]; 81 h[i]=f[u][v]; 82 } 83 printf("Case %d:\n", ++cas); 84 for(int i=0;i<q;i++){ 85 // int u=mp[s1[i]]; 86 // int v=mp[s2[i]]; 87 cout<<"The distance from "<<s1[i]<<" to "<<s2[i]<<" is "; 88 printf("%.0f",h[i]); 89 cout<<" parsecs."<<endl; 90 } 91 } 92 return 0; 93 }
标签:ecs mes for href ase ble max size out
原文地址:https://www.cnblogs.com/wsy107316/p/12247924.html