标签:memset return 包含 cst clu queue des 空间 表示
1 #include<iostream> 2 #include<queue> 3 #include<cmath> 4 #include<cstring> 5 #include<cstdio> 6 using namespace std; 7 struct sb 8 { 9 double x,y,z,r; 10 }a[201]; 11 double map[201][201]; 12 int n; 13 double calc(int i,int j) 14 { 15 long long a1=(a[i].x-a[j].x)*(a[i].x-a[j].x); 16 long long b1=(a[i].y-a[j].y)*(a[i].y-a[j].y); 17 long long c1=(a[i].z-a[j].z)*(a[i].z-a[j].z); 18 long long sum=a1+b1+c1; 19 double k=sqrt(sum); 20 if (k-a[i].r-a[j].r>0) return k-a[i].r-a[j].r; 21 else return 0; 22 } 23 int vis[201]; 24 double dis[201]; 25 void spfa() 26 { 27 queue<int> q; 28 for (int i=0;i<=n+1;i++) dis[i]=1000000000.0000; 29 memset(vis,0,sizeof(vis)); 30 dis[0]=0; vis[0]=1; q.push(0); 31 while (!q.empty()) 32 { 33 int x=q.front(); q.pop(); vis[x]=0; 34 for (int i=0;i<=n+1;i++) 35 { 36 if (map[x][i]>=0&&dis[i]>dis[x]+map[x][i]) 37 { 38 dis[i]=dis[x]+map[x][i]; 39 if (!vis[i]) 40 { 41 q.push(i); 42 vis[i]=1; 43 } 44 } 45 } 46 } 47 } 48 int main () 49 { 50 // freopen("warp.in","r",stdin); 51 // freopen("warp.out","w",stdout); 52 cin>>n; 53 while (n!=-1) 54 { 55 memset(map,0,sizeof(map)); 56 memset(a,0,sizeof(a)); 57 for (int i=1,x,y,z,r;i<=n;i++) 58 cin>>a[i].x>>a[i].y>>a[i].z>>a[i].r; 59 cin>>a[0].x>>a[0].y>>a[0].z; 60 cin>>a[n+1].x>>a[n+1].y>>a[n+1].z; 61 for (int i=0;i<=n+1;i++) 62 for (int j=i;j<=n+1;j++) 63 { 64 if (i==j) map[i][j]=-1; 65 else 66 map[i][j]=map[j][i]=calc(i,j); 67 } 68 spfa(); 69 cout<<round(dis[n+1]*10)<<endl; 70 cin>>n; 71 } 72 }
标签:memset return 包含 cst clu queue des 空间 表示
原文地址:https://www.cnblogs.com/zjzjzj/p/11391129.html