hdu 3405 world islands
生活随笔
收集整理的這篇文章主要介紹了
hdu 3405 world islands
小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
求刪點后最小的生成樹,n<50.。。。數據好弱,直接暴力枚舉就行。。。刪點的時候直接g[i][j]=INF就行了。
?
#include<iostream> #include<algorithm> #include<fstream> #include<string> #include<vector> #include<stack> #include<queue> #include<cstdio> #include<cstring> #include<cstdlib> #include<cmath> #include<map> #include<set> #define FF(i, a, b) for(i=a; i<b; i++) #define FD(i, a, b) for(i=a; i>b; i--) #define CLR(a, b) memset(a, b, sizeof(a)) #define LL long long #define CPY(a, b) memcpy(a, b, sizeof(b)) using namespace std; ofstream fout ("output.txt"); ifstream fin ("input.txt");const int maxn = 100; const double INF = 222222; int T, n; double g[maxn][maxn], low[maxn], x[maxn], y[maxn], tmp[maxn][maxn]; bool vis[maxn];double prim(int start) {double min, res=0;int i, j, pos;CLR(vis, 0);vis[start] = 1; pos = start;FF(i, 1, n+1) if(i!=pos) low[i] = g[pos][i];FF(i, 1, n){min = INF;FF(j, 1, n+1)if(vis[j] == 0 && min > low[j])min = low[j], pos = j;res += min;vis[pos] = 1;FF(j, 1, n+1)if(vis[j] == 0 && low[j] > g[pos][j])low[j] = g[pos][j];}return res; }int main() {scanf("%d", &T);while(T--){int i, j;scanf("%d", &n);FF(i, 1, n+1) scanf("%lf%lf", &x[i], &y[i]);FF(i, 1, n+1)FF(j, 1, n+1)g[i][j] = sqrt((x[i]-x[j])*(x[i]-x[j]) + (y[i]-y[j])*(y[i]-y[j]));double ans = INF*INF;FF(i, 1, n+1){CPY(tmp, g);FF(j, 1, n+1){g[i][j] = g[j][i] = INF;}ans = min(ans, prim(1));CPY(g, tmp);}printf("%.2lf\n", n < 3 ? 0 : ans-INF);}return 0; }?
?
轉載于:https://www.cnblogs.com/dyllove98/p/3188640.html
總結
以上是生活随笔為你收集整理的hdu 3405 world islands的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: android 播放声音 停止其他,An
- 下一篇: PDF 报告生成器:用 reportla