五块钱起家发大财
2008-06-03 16:05
148 查看
/* THE PROGRAM IS MADE BY PYY */ /*----------------------------------------------------------------------------// Copyright (c) 2012 panyanyany All rights reserved. URL : http://acm.hdu.edu.cn/showproblem.php?pid=1875 Name : 1875 畅通工程再续 Date : Tuesday, February 7, 2012 Time Stage : half an hour Result: 5325982 2012-02-07 16:12:09 Accepted 1875 15MS 272K 2551 B C++ pyy 5325978 2012-02-07 16:11:11 Compilation Error 1875 0MS 0K 2547 B C++ pyy Test Data : Review : Hdu 的系统好像会自动把math.h替换成cmath…… //----------------------------------------------------------------------------*/ #include <cstdio> #include <stdlib.h> #include <string.h> #include <math.h> #include <algorithm> using namespace std ; #define MEM(a, v) memset (a, v, sizeof (a)) // a for address, v for value #define max(x, y) ((x) > (y) ? (x) : (y)) #define min(x, y) ((x) < (y) ? (x) : (y)) #define INF (0x3f3f3f3f) #define MAXN (103) #define MAXE (MAXN*(MAXN-1)/2) #define DEBUG /##/ struct POINT { int x, y; }; int t, c ; int used[MAXN] ; double map[MAXN][MAXN], dist[MAXN] ; POINT apt[MAXN] ; #define POW(x) ((x)*(x)) #define DINF (1e10) inline double getdist (int i, int j) { double dis = sqrt(1.0*POW(apt[i].x - apt[j].x) + POW(apt[i].y - apt[j].y)) ; if (dis < 10.0 || dis > 1000.0) return DINF ; return dis ; } double Prim () { int i, j, iMinPath ; double sum, MinPath ; for (i = 1 ; i <= c ; ++i) dist[i] = map[1][i] ; MEM (used, 0) ; used[1] = true ; sum = 0.0 ; for (i = 1 ; i <= c-1 ; ++i) { MinPath = DINF ; for (j = 1 ; j <= c ; ++j) if (!used[j] && dist[j] < MinPath) { iMinPath = j ; MinPath = dist[j] ; } sum += MinPath ; if (sum >= DINF) break ; used[iMinPath] = true ; for (j = 1 ; j <= c ; ++j) if (!used[j] && dist[j] > map[iMinPath][j]) dist[j] = map[iMinPath][j] ; } return sum ; } int main() { int i, j ; int x, y ; double ans ; while (scanf ("%d", &t) != EOF) { while (t--) { scanf ("%d", &c) ; for (i = 1 ; i <= c ; ++i) { scanf ("%d%d", &apt[i].x, &apt[i].y) ; } // 遍历所有点,制图 for (i = 1 ; i <= c ; ++i) for (j = i+1 ; j <= c ; ++j) { map[i][j] = map[j][i] = getdist (i, j) ; } ans = Prim () ; if (ans >= DINF) puts ("oh!") ; else printf ("%.1lf\n", ans*100.0) ; } } return 0 ; }
相关文章推荐
- CCTV访25岁千万富翁戴志康:写论坛起家
- 王永庆:从借200元钱起家
- 商务视频起家,难抵统一通信魅惑
- 58同城姚劲波:以域名起家 从创业小子到亿万富翁
- 80后女孩5000元起家创业故事
- 惊呆了!一家小村子起家的企业,为何能风靡全世界?
- “白手”起家的故事里,创业者们有着这样一些无奈
- CCTV访25岁千万富翁戴志康:写论坛起家
- 王永庆:从借200元钱起家
- 全球9大高科技公司是如何起家的
- 58同城姚劲波:以域名起家 从创业小子到亿万富翁
- 80后女孩5000元起家创业故事
- 以IT培训起家的达内科技,如今半壁江山是非IT培训的其他职业教育了
- 博客起家了
- 王永庆:从借200元钱起家
- 在读大学生创业历程,350元起家到现在将近40万元的积蓄(1)
- 原来创业也可以这样:80后乞丐网上卖烧烤 500元起家赚了400万
- 使用malloc分别分配2KB的空间,然后用realloc调整为6KB、1MB、3MB、10MB空间,并且将这五块内存分别用“A”、“B”、“C”、“D”、“E”填充
- 从传统媒体起家,到直播行业旗手,是什么让战旗直播站在浪尖不下来