题意:

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. unity3d Human skin real time rendering plus 真实模拟人皮实时渲染 plus篇

    最近逃课做游戏,逃的有几门都要停考了,呵呵呵,百忙之中不忘超炒冷饭,感觉之前的人皮效果还是不够好,又改进了一些东西 首先上图 放大看细节 显而易见的比上次的效果要好很多,此次我把模型用3dmax进行了 ...

  2. Unity3d 真实的植物渲染

    好久没写shader了,有些生疏,刚弄了个植物shader,分享一下. 先上图片: 重点需要注意的是fragment shader的透明部分 需要如此声明 Tags{ "LightMode& ...

  3. IE的Cookie目录和临时缓存目录的关系

    1.IE的Cookie位置注册表设置: HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Explorer\Shell Folde ...

  4. git 分支策略

    转 http://www.ruanyifeng.com/blog/2012/07/git.html  作者: 阮一峰 如果你严肃对待编程,就必定会使用"版本管理系统"(Versio ...

  5. [kuangbin带你飞]专题十 匹配问题 二分图多重匹配

    二分图的多重匹配问题不同于普通的最大匹配中的"每个点只能有最多一条边" 而是"每个点连接的边数不超过自己的限定数量" 最大匹配所解决的问题一般是"每个 ...

  6. 【转】java 文件 读取目录下的所有文件(包括子目录)

    转自:http://www.cnblogs.com/pricks/archive/2009/11/11/1601044.html import java.io.File; import java.io ...

  7. U3D C# 实现AS3事件机制

    写了很多年的AS3,最近接触U3D感觉事件机制没AS3的爽.咬紧牙关一鼓作气 基于C# 的委托实现了一版.废话不多说上干货. EventDispatcher代码如下: using UnityEngin ...

  8. Debian自启动知识 2015-03-31 20:23 79人阅读 评论(0) 收藏

    Debian6添加了insserv用来代替update-rc.d.update-rc.d 就不多做介绍. Debian6里边要添加一个自动启动的服务需要先将启动脚本放在/etc/init.d,然后使用 ...

  9. percona-MYSQLGUI监控

    1.https://www.percona.com/blog/2016/05/26/monitoring-with-percona-app-for-grafana/ http://pmmdemo.pe ...

  10. A different twist on pre-compiling JSPs--reference

    I’ve blogged about this topic earlier and expressed my frustrations as to how web containers don’t p ...