题意:

H * W (W,H <= 10) 的矩阵A的某个元素A[i][j],从它出发到其他点的曼哈顿距离小于等于D的所有值的和S[i][j]除上可达点的数目,构成了矩阵B。给定矩阵B,求矩阵A。

题目先给宽再给高。。。坑我了一个小时

code

/*
暴力确定每个位置有到那些位置的曼哈顿距离小于D
然后对你n*m个未知数,n*m个方程进行高斯消元
*/
#include <iostream>
#include <cstdio>
#include <cmath>
#include <cstring>
using namespace std; const int MAXN = ;
int n, m, dx, cnt;
double A[MAXN][MAXN], ans[MAXN];
inline void build (int x, int y, int d) {
int k = ;
for (int i = , tol = ; i < n; ++i)
for (int j = ; j < m; ++j) {
if (abs (i - x) + abs (j - y) <= dx)
A[d][tol++] = , ++k;
else
A[d][tol++] = ;
}
A[d][cnt] *= k;
}
void Gauss() {
int i, j, k;
double tmp, big;
for (i = ; i < cnt; i++) {
for (big = , j = i; j < cnt; j++) {
if (abs (A[j][i]) > big) {
big = abs (A[j][i]);
k = j;
}
}
if (k != i) {
for (j = ; j <= cnt; j++)
swap (A[i][j], A[k][j]);
}
for (j = i + ; j < cnt; j++) {
if (A[j][i]) {
tmp = -A[j][i] / A[i][i];
for (k = i; k <= cnt; k++)
A[j][k] += tmp * A[i][k];
}
}
}
for (i = cnt - ; i >= ; i--) {
tmp = ;
for (j = i + ; j < cnt; j++)
tmp += A[i][j] * ans[j];
ans[i] = (A[i][j] - tmp) / A[i][i];
}
}
int main() {
int cs = ;
while (scanf ("%d %d %d", &m, &n, &dx), n) {
if (cs == ) cs = ;
else
putchar ();
cnt = n * m;
for (int i = , tol = ; i < n; ++i)
for (int j = ; j < m; ++j)
scanf ("%lf", &A[tol++][cnt]);
for (int i = , tol = ; i < n; ++i)
for (int j = ; j < m; ++j, ++tol)
build (i, j, tol);
Gauss ();
for (int i = , cnt = ; i < n; i++) {
for (int j = ; j < m; j++)
printf ("%8.2f", ans[cnt++]);
putchar ();
}
}
return ;
}

HDU 3359 Kind of a Blur(高斯消元)的更多相关文章

  1. hdu 3359 Kind of a Blur (高斯消元 浮点型)

    题目链接 题意: H * W (W,H <= 10) 的矩阵A的某个元素A[i][j],从它出发到其他点的曼哈顿距离小于等于D的所有值的和S[i][j]除上可达点的数目,构成了矩阵B.给定矩阵B ...

  2. HDU 5833 Zhu and 772002 (高斯消元)

    Zhu and 772002 题目链接: http://acm.hdu.edu.cn/showproblem.php?pid=5833 Description Zhu and 772002 are b ...

  3. 2016ACM/ICPC亚洲区沈阳站H - Guessing the Dice Roll HDU - 5955 ac自动机+概率dp+高斯消元

    http://acm.hdu.edu.cn/showproblem.php?pid=5955 题意:给你长度为l的n组数,每个数1-6,每次扔色子,问你每个串第一次被匹配的概率是多少 题解:先建成ac ...

  4. HDU 5119 Happy Matt Friends(DP || 高斯消元)

    题目链接 题意 : 给你n个数,让你从中挑K个数(K<=n)使得这k个数异或的和小于m,问你有多少种异或方式满足这个条件. 思路 : 正解据说是高斯消元.这里用DP做的,类似于背包,枚举的是异或 ...

  5. HDU 5833 Zhu and 772002 (数论+高斯消元)

    题目链接 题意:给定n个数,这n个数的素因子值不超过2000,从中取任意个数使其乘积为完全平方数,问有多少种取法. 题解:开始用素筛枚举写了半天TLE了,后来队友说高斯消元才想起来,果断用模板.赛后又 ...

  6. HDU3359 Kind of a Blur(高斯消元)

    建立方程后消元 #include<cstdio> #include<iostream> #include<cstdlib> #include<cstring& ...

  7. HDU 5833 Zhu and 772002(高斯消元)

    题意:给n个数,从n个数中抽取x(x>=1)个数,这x个数相乘为完全平方数,求一共有多少种取法,结果模1000000007. 思路:每个数可以拆成素数相乘的形式,例如: x1 2=2^1 * 3 ...

  8. hdu 3992 AC自动机上的高斯消元求期望

    Crazy Typewriter Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others) ...

  9. HDU 5544 Ba Gua Zhen dfs+高斯消元

    Ba Gua Zhen Problem Description During the Three-Kingdom period, there was a general named Xun Lu wh ...

随机推荐

  1. 1044 - Palindrome Partitioning(区间DP)

    题目大意: 给你一个字符串,问这个字符串最少有多少个回文串. 区间DP直接搞     #include<cstdio> #include<cstring> #include&l ...

  2. 【转】更新SDK后,打包APK时报 the zipalign tool was not found in the sdk

    原文网址:http://wyong.blog.51cto.com/1115465/1546632 原创作品,允许转载,转载时请务必以超链接形式标明文章 原始出处 .作者信息和本声明.否则将追究法律责任 ...

  3. C#验证码

    using System; using System.Drawing; using System.Drawing.Drawing2D; using System.Drawing.Imaging; us ...

  4. C#调用Web Service时的身份验证

    原理:webservice所在的系统中,在系统域中建立用于登录的软件的用户和密码,软件登录时将用户名.密码和登录的本机的域的名字通过webService的NetworkCredential传递到web ...

  5. Myeclipse 保存jsp异常Save FailedCompilation unit name must end with .java, or one of the registered Java-like extensions

    如图 解决方法:去掉jsp页面的调试断点

  6. POJ 1159 Palindrome 最长公共子序列的问题

    Description A palindrome is a symmetrical string, that is, a string read identically from left to ri ...

  7. Div 3 - SGU 105(找规律)

    分析:很容易知道序列1,2,3, 4,5, 6......与3的关系就是1,2, 0,1, 2,0,......如果是在一个数后面添加一个数就变成了这种序列1, 0, 0, 1, 0, 0, 1, 0 ...

  8. 自己生成非官方iPhone toolchain的头文件

    如果你已经搭建好非官方iPhone toolchain开发包,如果缺少某些头文件,可以用以下方法自己生成. 首先下载class-dump: http://www.codethecode.com/pro ...

  9. Servlet实现表单提交(MyEclipse10,Tomcat7.0,JDK1.7,)——Java Web练习(一)

    1.MyEclipse|File|New|Project|Web Project    填写Project Name:exServlet,点选Java EE 6.0(配套Tomcat7.0) 2.代码 ...

  10. hdu5127 Dogs' Candies CDQ分治 动态凸包

    传送门 题意 有三种操作 加入一个二元组\((x,y)\) 删除一个二元组\((x,y)\) 给出一个二元组\((a,b)\),问\(ax+by\)的最大值 题解 \(z=ax+by \Rightar ...