题意:

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. Android应用连接代理服务器状况监测解决

    最近项目里面有这样一个需求,由于项目涉密需要连接VPN通过网址映射去登录内部服务器,而且要通知客户vpn的连接状态.网上有许多类似的连接VPN的解决方案,我也尝试了很多种,下面先列出一种比较靠谱的方式 ...

  2. [PHP] 跳转以及回到原来的地址

    回到原来的地址: 1.PHP(PHP代码) Header('Location:'.$_SERVER["HTTP_REFERER"]); 2.JavaScript(相当于后退按钮,- ...

  3. Linux学习笔记3——Linux中常用系统管理命令

    stat 显示指定文件的相关信息,比ls命令显示内容更多 who 显示在线登录用户 hostname 显示主机名称 uname显示系统信息 top 显示当前系统中耗费资源最多的进程 ps 显示瞬间的进 ...

  4. 在unity3d中连接sql server

    虽然在Unity3D中能够通过PlayerPrefs类来保存和读取数据,但是一旦数据量增大,仅仅通过代码的方式存取数据,这样的工作量是非常大的.那么如何通过使用Sql Server数据库来存取数据呢? ...

  5. Unity-layermask的问题

    using UnityEngine; using System.Collections; public class NewBehaviourScript : MonoBehaviour { priva ...

  6. Reachability几个常用方法

    http://oncerios.diandian.com/post/2013-06-28/40050041969

  7. ZOJ 3761 Easy billiards 月赛E DFS

    题目链接:http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemCode=3761 题目大意:给定n个位置的小球,小球的运动方向只能是水平或者 ...

  8. Apache Mesos_百度百科

    Apache Mesos_百度百科 Apache Mesos

  9. Spring 连接数据库测试

    1.编写测试对象类 package model; import java.io.Serializable; /** * Created by xumao on 2016/12/5. */ public ...

  10. codeforces 710C

    C. Magic Odd Square time limit per test 1 second memory limit per test 256 megabytes input standard ...