标签:des style blog http color io os ar java
Time Limit: 30000/15000 MS (Java/Others) Memory Limit: 65536/65536 K (Java/Others)
Total Submission(s): 543 Accepted Submission(s): 344
Special Judge
1 #include<iostream> 2 #include<cstdio> 3 #include<cstdlib> 4 #include<ctime> 5 #include<cstring> 6 #include<string> 7 #include<map> 8 #include<set> 9 #include<cmath> 10 #include<stack> 11 #include<queue> 12 #include<vector> 13 #include<algorithm> 14 #define inf 0x3f3f3f3f 15 #define PI acos(-1.0) 16 #define eps 1e-6 17 #define LL long long 18 #define MEM(a,b) memset(a,b,sizeof(a)) 19 #define PB push_back 20 #define MP make_pair 21 #define PQ priority_queue 22 #define IN freopen("in.txt","r",stdin); 23 #define OUT freopen("out.txt","w",stdout); 24 #define BUG printf("bug************bug************bug\n"); 25 26 using namespace std; 27 28 const int N=60; 29 double f[2][N][N]; 30 double p[N]; 31 vector <int> G[N]; 32 33 int main() 34 { 35 int T,n,m,d,x,y; 36 scanf("%d",&T); 37 while (T--){ 38 memset(p,0,sizeof(p)); 39 memset(f,0,sizeof(f)); 40 scanf("%d%d%d",&n,&m,&d); 41 for (int i=1;i<=n;i++) G[i].clear(); 42 for (int i=1;i<=m;i++){ 43 scanf("%d%d",&x,&y); 44 G[x].push_back(y); 45 G[y].push_back(x); 46 } 47 for (int i=1;i<=n;i++) 48 for (int j=1;j<=n;j++) f[0][i][j]=1.0/n; 49 50 for (int k=0;k<d;k++){ 51 memset(f[(k+1)&1],0,sizeof(f[(k+1)&1])); 52 for (int i=1;i<=n;i++){ 53 for (int j=1;j<=n;j++){ 54 if (i==j) continue; 55 int u=G[j].size(); 56 for (int v=0;v<u;v++){ 57 int x=G[j][v]; 58 f[(k+1)&1][i][x]+=f[k&1][i][j]/u; 59 } 60 } 61 p[i]+=f[(k+1)&1][i][i]; 62 } 63 } 64 for (int i=1;i<=n;i++) 65 printf("%0.10lf\n",1-p[i]-1.0/n); 66 } 67 } 68 69 /* 70 2 71 5 10 2 72 1 2 73 2 3 74 3 4 75 4 5 76 1 5 77 2 4 78 3 5 79 2 5 80 1 4 81 1 3 82 1 83 3 4 4 84 1 2 85 2 3 86 3 1 87 */
标签:des style blog http color io os ar java
原文地址:http://www.cnblogs.com/wzb-hust/p/4029565.html