标签:des style blog http java color
Time Limit: 10000/5000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)
Total Submission(s): 348 Accepted Submission(s): 217
Special Judge
1 #include <iostream> 2 #include <cstdio> 3 #include <cstring> 4 #include <algorithm> 5 #include <cmath> 6 7 8 using namespace std; 9 10 #define read() freopen("sw.in", "r", stdin) 11 12 const double eps = 1e-9; 13 const int MAX = 305; 14 double p; 15 double a[MAX][MAX]; 16 int id[25][25]; 17 int len = 0; 18 19 void init() { 20 memset(id, -1 ,sizeof(id)); 21 for (int i = 0; i < 20; ++i) { 22 for (int j = 0; j <= i; ++j) { 23 id[i][j] = len++; 24 } 25 } 26 //printf("len = %d\n", len); 27 28 } 29 30 void solve( int &n) { 31 int r; 32 for (int i = 0; i < n; ++i) { 33 r = i; 34 for (int j = i + 1; j < n; ++j) { 35 if (fabs(a[j][i]) > fabs(a[r][i])) r = j; 36 } 37 if (r != i) for (int j = 0; j <= n; ++j) swap(a[r][j], a[i][j]); 38 39 for (int j = n; j >= i; --j) { 40 for (int k = i + 1; k < n; ++k) { 41 a[k][j] -= a[k][i] / a[i][i] * a[i][j]; 42 } 43 } 44 } 45 46 for (int i = n - 1; i >= 0; --i) { 47 for (int j = i + 1; j < n; ++j) { 48 a[i][n] -= a[j][n] * a[i][j]; 49 } 50 a[i][n] /= a[i][i]; 51 } 52 53 //for (int i = 0; i < n; ++i) 54 printf("%.6f\n", a[0][n]); 55 } 56 int main() 57 { 58 // read(); 59 init(); 60 while (~scanf("%lf", &p)) { 61 memset(a, 0, sizeof(a)); 62 //cout << p << endl; 63 int u, v; 64 for (int i = 0; i < 20; ++i) { 65 for (int j = 0; j < i; ++j) { 66 u = id[i][j]; 67 68 a[ u ][ u ] = 1; 69 a[ u ][ len ] = 1; 70 v = id[i][ max(0, j - 2)]; 71 a[u][v] -= (1.0 - p); 72 v = id[i][j + 1]; 73 a[ u ][ v ] -= p; 74 75 76 } 77 u = id[i][i]; 78 a[ u ][ u ] = 1; 79 a[ u ][len] = 1; 80 v = id[i][ max(0, i - 2) ]; 81 a[ u ][ v ] -= 1 - p; 82 v = id[i + 1][ i ]; 83 a[ u] [v ] -= p; 84 85 } 86 87 solve( len); 88 89 90 } 91 //cout << "Hello world!" << endl; 92 return 0; 93 }
标签:des style blog http java color
原文地址:http://www.cnblogs.com/hyxsolitude/p/3863383.html