HDOJ 3359 Kind of a Blur
用高斯消元对高斯模糊的图像还原....
Kind of a Blur
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)
Total Submission(s): 1321 Accepted Submission(s): 383
topics in image processing. This process is called deblurring, which will be your task for this problem.
In this problem, all images are in grey-scale (no colours). Images are represented as a 2 dimensional matrix of real numbers, where each cell corresponds to the brightness of the corresponding pixel. Although not mathematically accurate, one way to describe
a blurred image is through averaging all the pixels that are within (less than or equal to) a certain Manhattan distance?
from each pixel (including the pixel itself ). Here's an example of how to calculate the blurring of a 3x3 image with a blurring distance
of 1:

Given the blurred version of an image, we are interested in reconstructing the original version assuming that the image was blurred as explained above.



<= min(W/2,H/2)). The remaining H lines specify the gray-level of each pixel in the blurred image. Each line specifies W non-negative real numbers given up to the 2nd decimal place. The value of all the given real numbers will be less than 100.
Zero or more lines (made entirely of white spaces) may appear between cases. The last line of the input file consists of three zeros.
test cases by an empty line. Do not print an empty line after the last test case. It is guaranteed that there is exactly one unique solution for every test case.
2 2 1
1 1
1 1 3 3 1
19 14 20
12 15 18
13 14 16 4 4 2
14 15 14 15
14 15 14 15
14 15 14 15
14 15 14 15 0 0 0
1.00 1.00
1.00 1.00 2.00 30.00 17.00
25.00 7.00 13.00
14.00 0.00 35.00 1.00 27.00 2.00 28.00
21.00 12.00 17.00 8.00
21.00 12.00 17.00 8.00
1.00 27.00 2.00 28.00HintThe Manhattan Distance (sometimes called the Taxicab distance) between
two points is the sum of the (absolute) difference of their coordinates.
The grid on the lower right illustrates the Manhattan distances from the grayed cell.
#include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <cmath> using namespace std; const double eps=1e-8;
const int maxn=130; double data[maxn/10][maxn/10],a[maxn][maxn],x[maxn];
int n,m,d; int equ,val; void Gauss()
{
int k,col,mar;
for(k=0,col=0;k<equ&&col<val;k++,col++)
{
mar=k;
for(int i=k+1;i<equ;i++)
{
if(fabs(a[i][col])>fabs(a[mar][col]))
mar=i;
}
if(fabs(a[mar][col])<eps) return ;
if(k!=mar)
{
for(int i=col;i<val;i++)
swap(a[k][i],a[mar][i]);
swap(x[k],x[mar]);
}
x[k]/=a[k][col];
for(int i=col+1;i<val;i++)
a[k][i]/=a[k][col];
a[k][col]=1.;
for(int i=0;i<equ;i++)
{
if(i==k) continue;
x[i]-=x[k]*a[i][col];
for(int j=col+1;j<val;j++)
a[i][j]-=a[k][j]*a[i][col];
a[i][col]=0;
}
}
} int main()
{
bool fst=false;
while(scanf("%d%d%d",&m,&n,&d)!=EOF)
{
if(n==0&&m==0) break;
if(fst) putchar(10);
else fst=true;
memset(a,0,sizeof(a));
memset(x,0,sizeof(x));
for(int i=0;i<n;i++)
{
for(int j=0;j<m;j++)
{
scanf("%lf",&data[i][j]);
int cnt=0;
int t1=i*m+j,t2=0;
for(int ii=0;ii<n;ii++)
{
for(int jj=0;jj<m;jj++)
{
if(abs(i-ii)+abs(j-jj)<=d)
{
t2=ii*m+jj;
a[t2][t1]=1.;
cnt++;
}
}
}
x[t1]=data[i][j]*cnt;
}
}
equ=val=n*m;
Gauss();
for(int i=0;i<n;i++)
{
for(int j=0;j<m;j++)
{
printf("%8.2lf",x[i*m+j]);
}
putchar(10);
}
}
return 0;
}
HDOJ 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 3359 Kind of a Blur(高斯消元)
题意: H * W (W,H <= 10) 的矩阵A的某个元素A[i][j],从它出发到其他点的曼哈顿距离小于等于D的所有值的和S[i][j]除上可达点的数目,构成了矩阵B.给定矩阵B,求矩阵A ...
- HDOJ 1009. Fat Mouse' Trade 贪心 结构体排序
FatMouse' Trade Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others) ...
- HDOJ 2317. Nasty Hacks 模拟水题
Nasty Hacks Time Limit: 3000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others) Tota ...
- HDOJ 1326. Box of Bricks 纯水题
Box of Bricks Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others) To ...
- 解决css3毛玻璃效果(blur)有白边问题
做一个登录页,全屏背景图毛玻璃效果,实现方法如下: HTML: <body> <div class="login-wrap"> <div class= ...
- js(jquery)解决input元素的blur事件和其他非表单元素的click事件冲突的方法
HTML结构:很简单,就一个input,一个div,能说明问题就OK了: <input type="text" value="默认值"><br ...
- blur和click事件的先后顺序问题
这两个同时用会有冲突.懒得翻译了,需要的自己看哈. 以下摘自stackoverflow. I have an input field, where I try to make autocomplete ...
- HDOJ 1004 Let the Balloon Rise
Problem Description Contest time again! How excited it is to see balloons floating around. But to te ...
随机推荐
- 快速配置vim+ctags+taglist
实验平台:centos 7 1.安装vim编辑器 点击(此处)折叠或打开 $sudo yum install vim 并编辑配置文件.vimrc文件,放在主目录下/home/developer 参考配 ...
- saltstack 实现系统初始化
1.整体结构如下 [root@zabbix init]# pwd /srv/salt/base/init [root@zabbix init]# ll total -rw-r--r-- root ro ...
- 转: listview异步图片加载之优化篇(android)
Listview异步加载之优化篇 关于listview的异步加载,网上其实很多示例了,总体思想差不多,不过很多版本或是有bug,或是有性能问题有待优化.有鉴于此,本人在网上找了个相对理想的版本并在此基 ...
- Mysql 乱码配置
转自: http://www.ha97.com/5359.html 一.登录MySQL查看用SHOW VARIABLES LIKE ‘character%’;下字符集,显示如下: +--------- ...
- 《Linux命令、编辑器与shell编程》第三版 学习笔记---001
Linux概述 1.具有内核编程接口 2.支持多用户(同时) 3.支持多任务 4.支持安全的分层文件系统 a.标准 b.链接 c.权限 5.shell(命令解释器和编程语言) a.文件名生成(通配符和 ...
- mysql运维必会的一些知识点整理(转自民工哥)
(1)基础笔试命令考察 1.开启MySQL服务 /etc/init.d/mysqld start service mysqld start systemctl start mysqld 2.检测端口是 ...
- PHP将两个二维数组合并为一个二维数组的方法
$a = array(0 => Array(id => 66,class_name => math),1 => Array(id => 67,class_name =&g ...
- React Native WebView关闭缓存
React Native WebView关闭缓存 网上搜索没有找到关闭React Native下webview控件的缓存的方法,经测试找到解决方案,记录如下 核心思路:通过请求时设置请求头,使页面缓存 ...
- NYOJ 71 乘船问题【贪心】
时间复杂度O(n) 有n个人,第i个人的重量为w[i],每艘船的最大载重量均为c,且最多只能乘两个人.用最少的船装载所有人. 思路:从最轻的开始考虑,让最轻的和最重的一条船,若超出重量则可判定最重的只 ...
- php 快速上手
基本语法 PHP 标记 php 以 <?php 和 ?>(可以选用, 推荐, 防止输出空白) 作为开始和结束标记. 打印 php 有 echo(多参数) 和 print(单参数) 可以用于 ...