HDU 3359 Kind of a Blur(高斯消元)
题意:
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(高斯消元)的更多相关文章
- hdu 3359 Kind of a Blur (高斯消元 浮点型)
题目链接 题意: H * W (W,H <= 10) 的矩阵A的某个元素A[i][j],从它出发到其他点的曼哈顿距离小于等于D的所有值的和S[i][j]除上可达点的数目,构成了矩阵B.给定矩阵B ...
- HDU 5833 Zhu and 772002 (高斯消元)
Zhu and 772002 题目链接: http://acm.hdu.edu.cn/showproblem.php?pid=5833 Description Zhu and 772002 are b ...
- 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 ...
- HDU 5119 Happy Matt Friends(DP || 高斯消元)
题目链接 题意 : 给你n个数,让你从中挑K个数(K<=n)使得这k个数异或的和小于m,问你有多少种异或方式满足这个条件. 思路 : 正解据说是高斯消元.这里用DP做的,类似于背包,枚举的是异或 ...
- HDU 5833 Zhu and 772002 (数论+高斯消元)
题目链接 题意:给定n个数,这n个数的素因子值不超过2000,从中取任意个数使其乘积为完全平方数,问有多少种取法. 题解:开始用素筛枚举写了半天TLE了,后来队友说高斯消元才想起来,果断用模板.赛后又 ...
- HDU3359 Kind of a Blur(高斯消元)
建立方程后消元 #include<cstdio> #include<iostream> #include<cstdlib> #include<cstring& ...
- HDU 5833 Zhu and 772002(高斯消元)
题意:给n个数,从n个数中抽取x(x>=1)个数,这x个数相乘为完全平方数,求一共有多少种取法,结果模1000000007. 思路:每个数可以拆成素数相乘的形式,例如: x1 2=2^1 * 3 ...
- hdu 3992 AC自动机上的高斯消元求期望
Crazy Typewriter Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others) ...
- HDU 5544 Ba Gua Zhen dfs+高斯消元
Ba Gua Zhen Problem Description During the Three-Kingdom period, there was a general named Xun Lu wh ...
随机推荐
- android滑动删除的多种实现方式(一)
个人习惯,先上图 同事是个妹子(这点很重要),写滑动删除动能的时候用到了SwipeLayout,然后悲催的是,滑动时间被拦截了,解决方法先不提,在(一)中先讲解SwipeLayout下载listvie ...
- MyEclipse Spring被删之后,如何在myeclipse里面重新导入
1.找到项目文件 2.用记事本打开 .project 把里面涉及到spring的全部删除就可以了.
- A configuration error occurred during startup. Please verify the preference field with the prompt: Cannot connect to vm
1.报错图 解决方法: Window->Preferences->MyEclipse Enterprice Workbench->Servers->Tomcat->选择你 ...
- 关于日历控件My97DatePicker 在IE6下出现“无法打开站点,已终止操作”
1.My97DatePicker 官方:http://www.my97.net2.在IE6下出现“无法打开站点,已终止操作”的解决办法(转): .这是一个绝对有效的方法,但是会丢失跨越iframe的特 ...
- 对javabean的内省操作
import java.beans.BeanInfo; import java.beans.IntrospectionException; import java.beans.Introspector ...
- 一些技术blog和安全blog
1.安全blog: http://zenxds.com/blog/ http://navisec.it/ http://huaidan.org/ http://leapar.lofter.com/ h ...
- HIBERNATE 01
2017年1月8日 {LJ?Dragon}[标题]Hibernate基础知识简介_01 {LJ?Dragon}[Links]Hibernate注解详解 {LJ?Dragon}[Daily]特种部队2, ...
- bzoj3907: 网格
http://www.cnblogs.com/Tunix/p/4354348.html #include<cstdio> #include<cstring> #include& ...
- AlphaDict 软件公布
今天 Release 了 1.1. 主要是移植到了 window 平台, 无须安装,直接执行. 对 UI 又一次进行了设计,应该比之前好看多了. 加入了 生词本 功能,方便 学习外语. ------- ...
- Python获取当前时间 分类: python 2014-11-08 19:02 132人阅读 评论(0) 收藏
Python有专门的time模块可以供调用. <span style="font-size:14px;">import time print time.time()&l ...