hdu3359 Kind of a Blur
Posted ws_ccd
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了hdu3359 Kind of a Blur相关的知识,希望对你有一定的参考价值。
因为变化出来的是平均数,那么就可以对每一个变化出来的列方程,直接高斯消元就行了。
1 #include<bits/stdc++.h> 2 #define N 100005 3 #define LL long long 4 #define inf 0x3f3f3f3f 5 #define ls c[x][0] 6 #define rs c[x][1] 7 using namespace std; 8 inline int ra() 9 { 10 int x=0,f=1; char ch=getchar(); 11 while (ch<‘0‘ || ch>‘9‘) {if (ch==‘-‘) f=-1; ch=getchar();} 12 while (ch>=‘0‘ && ch<=‘9‘) {x=x*10+ch-‘0‘; ch=getchar();} 13 return x*f; 14 } 15 const int maxn=105; 16 const double eps=1e-8; 17 double a[maxn][maxn]; 18 double ave[15][15]; 19 double b[maxn]; 20 void guass(int n, int m) 21 { 22 int equ=n*m,var=n*m; 23 for (int row=1,col=1; row<=equ && col<=var; row++,col++) 24 { 25 int maxr=row; 26 for (int i=row; i<=equ; i++) 27 if (fabs(a[i][col])-fabs(a[maxr][col])>eps) 28 maxr=i; 29 if (fabs(a[maxr][col])<eps) 30 { 31 row--; continue; 32 } 33 if (maxr!=row) 34 for (int j=col; j<=var+1; j++) 35 swap(a[maxr][j],a[row][j]); 36 for (int i=row+1; i<=equ; i++) 37 if (fabs(a[i][col])>eps) 38 { 39 double s=a[i][col]/a[row][col]; 40 for (int j=col; j<=var+1; j++) 41 a[i][j]-=a[row][j]*s; 42 } 43 } 44 for (int i=equ; i>=1; i--) 45 { 46 double tmp=a[i][var+1]; 47 for (int j=i+1; j<=var; j++) 48 tmp-=a[i][j]*b[j]; 49 b[i]=tmp/a[i][i]; 50 } 51 } 52 int main() 53 { 54 int n,m,d; int first=1; 55 while (~scanf("%d%d%d",&m,&n,&d)) 56 { 57 memset(a,0,sizeof(a)); 58 if (n+m+d==0) break; 59 for (int i=1; i<=n; i++) 60 for (int j=1; j<=m; j++) 61 scanf("%lf",&ave[i][j]); 62 for (int k=1; k<=n*m; k++) 63 { 64 int x=(k-1)/m+1,y=k%m; if (!y) y=m; 65 double num=0; 66 for (int i=1; i<=n; i++) 67 for (int j=1; j<=m; j++) 68 if (abs(i-x)+abs(j-y)<=d) 69 a[k][(i-1)*m+j]=1,num++; 70 a[k][n*m+1]=num*ave[x][y]; 71 } 72 guass(n,m); 73 if (first) first=0; else cout<<endl; 74 for (int i=1; i<=n*m; i++) 75 { 76 printf("%8.2lf",b[i]); 77 if (i%m==0) printf("\n"); 78 } 79 } 80 return 0; 81 }
以上是关于hdu3359 Kind of a Blur的主要内容,如果未能解决你的问题,请参考以下文章
HDU3306—Another kind of Fibonacci
hdu3306:Another kind of Fibonacci
hdu 3306 Another kind of Fibonacci 矩阵快速幂