BZOJ1491 [NOI2007] 社交网络
题目链接:http://www.lydsy.com/JudgeOnline/problem.php?id=1491
Description
Input
Output
输出文件包括n 行,每行一个实数,精确到小数点后3 位。第i 行的实数表 示结点i 在社交网络中的重要程度。
写此题遭遇玄学(疑似?)
数组开成int计算结果时用转换成double就WA一个点,开成double就A
一道史上最水的NOI题目硬是废了我晚自习,本来还想写作业的
刚开学不太想打难一点的题
嗯想换一个BZOJ号
1 #include <iostream> 2 #include <cstdio> 3 #include <algorithm> 4 #include <cstring> 5 #define rep(i,l,r) for(int i=l; i<=r; i++) 6 #define clr(x,y) memset(x,y,sizeof(x)) 7 using namespace std; 8 const int INF = 0x3f3f3f3f; 9 const int maxn = 110; 10 inline int read(){ 11 int ans = 0, f = 1; 12 char c = getchar(); 13 for(; !isdigit(c); c = getchar()) 14 if (c == '-') f = -1; 15 for(; isdigit(c); c = getchar()) 16 ans = ans * 10 + c - '0'; 17 return ans * f; 18 } 19 int n,m,x,y,z; 20 double d[maxn][maxn],c[maxn][maxn]; 21 int main(){ 22 n = read(); m = read(); 23 rep(i,1,n){ 24 rep(j,1,n) d[i][j] = INF, c[i][j] = 1; 25 d[i][i] = 0; 26 } 27 rep(i,1,m){ 28 x = read(); y = read(); z = read(); 29 d[x][y] = d[y][x] = z; 30 } 31 rep(k,1,n) rep(i,1,n) rep(j,1,n) if (i != j && k != i && k != j){ 32 if (d[i][k] + d[k][j] < d[i][j]){ 33 d[i][j] = d[i][k] + d[k][j]; c[i][j] = c[i][k] * c[k][j]; 34 } 35 else if (d[i][k] + d[k][j] == d[i][j]) c[i][j] += c[i][k] * c[k][j]; 36 } 37 rep(k,1,n){ 38 double ans = 0; 39 rep(i,1,n) rep(j,1,n) if (i != j && k != i && k != j){ 40 if (d[i][k] + d[k][j] == d[i][j]) ans += c[i][k] * c[k][j] / c[i][j]; 41 } 42 printf("%.3lf\n",ans); 43 } 44 return 0; 45 }