标签:deb amp with bottom specified == tin nsis sam
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)
Total Submission(s): 2754 Accepted Submission(s): 751
1 //2017-08-05 2 #include <cstdio> 3 #include <cstring> 4 #include <iostream> 5 #include <algorithm> 6 #include <cmath> 7 8 using namespace std; 9 10 const int N = 15; 11 const double eps = 1e-9; 12 int n, m, d; 13 double G[N][N], A[N*N][N*N], x[N*N]; 14 int equ, var; 15 16 int Gauss(){ 17 int i, j, k, col, max_r; 18 for(k = 0, col = 0; k < equ && col < var; k++, col++){ 19 max_r = k; 20 for(i = k+1; i < equ; i++) 21 if(fabs(A[i][col]) > fabs(A[max_r][col])) 22 max_r = i; 23 if(fabs(A[max_r][col]) < eps)return 0; 24 if(k != max_r){ 25 for(j = col; j < var; j++) 26 swap(A[k][j], A[max_r][j]); 27 swap(x[k], x[max_r]); 28 } 29 x[k] /= A[k][col]; 30 for(j = col+1; j < var; j++) 31 A[k][j] /= A[k][col]; 32 A[k][col] = 1; 33 for(i = 0; i < equ; i++) 34 if(i != k){ 35 x[i] -= x[k]*A[i][k]; 36 for(j = col+1; j < var; j++) 37 A[i][j] -= A[k][j]*A[i][col]; 38 A[i][col] = 0; 39 } 40 } 41 return 1; 42 } 43 44 int main() 45 { 46 bool fg = true; 47 while(scanf("%d%d%d", &m, &n, &d)!=EOF){ 48 if(!n && !m)break; 49 if(!fg)printf("\n"); 50 fg = false; 51 memset(A, 0, sizeof(A)); 52 for(int i = 0; i < n; i++) 53 for(int j = 0; j < m; j++){ 54 scanf("%lf", &G[i][j]); 55 x[i*m+j] = G[i][j]; 56 } 57 for(int i = 0; i < n*m; i++){ 58 int cnt = 0; 59 for(int j = 0; j < n*m; j++){ 60 int x = i/m; 61 int y = i%m; 62 int dx = j/m; 63 int dy = j%m; 64 if(abs(x-dx)+abs(y-dy) <= d){ 65 A[i][j] = 1.0; 66 cnt++; 67 }else A[i][j] = 0.0; 68 } 69 x[i] *= cnt; 70 } 71 equ = n*m; 72 var = n*m; 73 Gauss(); 74 for(int i = 0; i < n*m; i++){ 75 if(i % m == m-1)printf("%8.2lf\n", x[i]); 76 else printf("%8.2lf", x[i]); 77 } 78 } 79 80 return 0; 81 }
HDU3359(SummerTrainingDay05-I 高斯消元)
标签:deb amp with bottom specified == tin nsis sam
原文地址:http://www.cnblogs.com/Penn000/p/7291709.html