标签:oid cst lin ash .com status sea 接受 include
身边的两位巨犇说我太菜了——“居然用期望乘概率,简直是胡扯,*&^&$#$”
1 #include <cstdio> 2 #include <cstring> 3 4 const int mxn = 305; 5 const int mxm = 50005; 6 7 int n, m, p, q; 8 9 double G[mxn][mxn]; 10 11 struct edge { 12 int x, y; 13 }E[mxm]; 14 15 int cnt[mxn]; 16 17 double K, F[mxn]; 18 19 signed main(void) { 20 scanf("%d%d%d%d", &n, &m, &p, &q); 21 22 K = 1.0 * p / q; 23 24 for (int i = 1; i <= m; ++i) 25 scanf("%d%d", &E[i].x, &E[i].y); 26 27 for (int i = 1; i <= m; ++i) 28 ++cnt[E[i].x], ++cnt[E[i].y]; 29 30 for (int i = 1; i <= m; ++i) 31 G[E[i].x][E[i].y] -= (1.0 - K) / cnt[E[i].y], 32 G[E[i].y][E[i].x] -= (1.0 - K) / cnt[E[i].x]; 33 34 for (int i = 1; i <= n; ++i) 35 G[i][i] = 1.0; 36 37 G[1][n + 1] = 1.0; 38 39 for (int i = 1; i <= n; ++i) 40 for (int j = 1; j <= n; ++j)if (i != j){ 41 double t = G[j][i] / G[i][i]; 42 for (int k = 1; k <= n + 1; ++k) 43 G[j][k] -= t * G[i][k]; 44 } 45 46 for (int i = 1; i <= n; ++i) 47 F[i] = G[i][n + 1] / G[i][i]; 48 49 for (int i = 1; i <= n; ++i) 50 printf("%.9lf\n", F[i] * K); 51 }
@Author: YouSiki
BZOJ 1778: [Usaco2010 Hol]Dotp 驱逐猪猡
标签:oid cst lin ash .com status sea 接受 include
原文地址:http://www.cnblogs.com/yousiki/p/6498404.html