本文主要是介绍[HDU3359]Kind of a Blur 高斯消元 陨石巨坑,希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!
这是一道陨石巨坑的题 陨石巨坑 巨坑
下面我讲一下坑在哪里 果断换红色
1.先读入宽度 !! 这该死的样例全是n*n
2.读入的是double !! 这该死的样例全是int
果断被坑N久 思路很简单 n*n个方程消元就行了
#include<cstdio>
#include<algorithm>
#include<cstdlib>
#include<cstring>
#include<cmath>
using namespace std;
#define eps 1e-6
#define EPS 1e-13
#define MAXN 200
#define MAXM 200
int n, m, D;
double pic[MAXN+10][MAXN+10];
int sgn(const double &x) { return (x > eps) - (x < -eps); }
int ans[MAXN*MAXN+10];
template <int maxn, int maxm>
struct Maxtrix{int N, M, rank;Maxtrix() {}Maxtrix(int x, int y) { N = x; M = y; }double A[maxn+10][maxm+10];void init() { memset(A, 0, sizeof(A)); }void read(){for(int i = 0; i < N; i++)for(int j = 0; j <= M; j++)scanf("%lf", &A[i][j]);}void Gauss(){for(int i = 0, j = 0; i < N && j < N; i++, j++){int r = i;for(int k = i + 1; k < N; k++) if(fabs(A[k][j]) > fabs(A[r][j])) r = k;if(r != i) for(int k = 0; k <= M; k++) swap(A[r][k], A[i][k]);if(fabs(A[i][j]) < EPS) {i--;continue;}for(int k = 0; k < N; k++){if(i == k) continue;double f = A[k][j] / A[i][j];for(int l = j; l <= M; l++) A[k][l] -= f * A[i][l];}}}
};
Maxtrix <MAXN, MAXM> A;
int dis(int x1, int y1, int x2, int y2)
{return fabs(x1 - x2) + fabs(y1 - y2);
}
int id(int x, int y)
{return x * m + y;
}
void Build(int x, int y)
{int cnt = 0;int ID = id(x, y);for(int i = 0; i < n; i++)for(int j = 0; j < m; j++)if(dis(i, j, x, y) <= D){int tid = id(i, j);A.A[ID][tid] = 1;cnt++;}A.A[ID][n*m] = pic[x][y] * cnt;
}
int main()
{int kase = 0;while(scanf("%d%d%d", &m, &n, &D) == 3 && n+m+D){if(kase) puts("");for(int i = 0; i < n; i++)for(int j = 0; j < m; j++)scanf("%lf", &pic[i][j]);A.init();A.N = n*m;A.M = n*m+1;for(int i = 0; i < n; i++)for(int j = 0; j < m; j++)Build(i, j);A.Gauss();for(int i = 0; i < n; i++){for(int j = 0; j < m; j++) printf("%8.2lf", A.A[id(i, j)][n*m] / A.A[id(i, j)][id(i, j)]);puts("");}kase++;}
}
这篇关于[HDU3359]Kind of a Blur 高斯消元 陨石巨坑的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!