Kind of a Blur

Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)
Total Submission(s): 2754    Accepted Submission(s): 751

Problem Description

Image blurring occurs when the object being captured is out of the camera's focus. The top two figures on the right are an example of an image and its blurred version. Restoring the original image given only the blurred version is one of the most interesting 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.

 

Input

Input consists of several test cases. Each case is specified on H + 1 lines. The first line specifies three non negative integers specifying the width W, the height H of the blurred image and the blurring distance D respectively where (1<= W,H <= 10) and (D <= 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.
 

Output

For each test case, print a W * H matrix of real numbers specifying the deblurred version of the image. Each element in the matrix should be approximated to 2 decimal places and right justified in a field of width 8. Separate the output of each two consecutive 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.
 

Sample Input

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

 

Sample Output

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.00

Hint

The 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.

 

Source

 
高斯消元,居然是先输入宽,再输入高,被这个WA了好几发。。。
 //2017-08-05
#include <cstdio>
#include <cstring>
#include <iostream>
#include <algorithm>
#include <cmath> using namespace std; const int N = ;
const double eps = 1e-;
int n, m, d;
double G[N][N], A[N*N][N*N], x[N*N];
int equ, var; int Gauss(){
int i, j, k, col, max_r;
for(k = , col = ; k < equ && col < var; k++, col++){
max_r = k;
for(i = k+; i < equ; i++)
if(fabs(A[i][col]) > fabs(A[max_r][col]))
max_r = i;
if(fabs(A[max_r][col]) < eps)return ;
if(k != max_r){
for(j = col; j < var; j++)
swap(A[k][j], A[max_r][j]);
swap(x[k], x[max_r]);
}
x[k] /= A[k][col];
for(j = col+; j < var; j++)
A[k][j] /= A[k][col];
A[k][col] = ;
for(i = ; i < equ; i++)
if(i != k){
x[i] -= x[k]*A[i][k];
for(j = col+; j < var; j++)
A[i][j] -= A[k][j]*A[i][col];
A[i][col] = ;
}
}
return ;
} int main()
{
bool fg = true;
while(scanf("%d%d%d", &m, &n, &d)!=EOF){
if(!n && !m)break;
if(!fg)printf("\n");
fg = false;
memset(A, , sizeof(A));
for(int i = ; i < n; i++)
for(int j = ; j < m; j++){
scanf("%lf", &G[i][j]);
x[i*m+j] = G[i][j];
}
for(int i = ; i < n*m; i++){
int cnt = ;
for(int j = ; j < n*m; j++){
int x = i/m;
int y = i%m;
int dx = j/m;
int dy = j%m;
if(abs(x-dx)+abs(y-dy) <= d){
A[i][j] = 1.0;
cnt++;
}else A[i][j] = 0.0;
}
x[i] *= cnt;
}
equ = n*m;
var = n*m;
Gauss();
for(int i = ; i < n*m; i++){
if(i % m == m-)printf("%8.2lf\n", x[i]);
else printf("%8.2lf", x[i]);
}
} return ;
}

HDU3359(SummerTrainingDay05-I 高斯消元)的更多相关文章

  1. 【BZOJ-3143】游走 高斯消元 + 概率期望

    3143: [Hnoi2013]游走 Time Limit: 10 Sec  Memory Limit: 128 MBSubmit: 2264  Solved: 987[Submit][Status] ...

  2. 【BZOJ-3270】博物馆 高斯消元 + 概率期望

    3270: 博物馆 Time Limit: 30 Sec  Memory Limit: 128 MBSubmit: 292  Solved: 158[Submit][Status][Discuss] ...

  3. *POJ 1222 高斯消元

    EXTENDED LIGHTS OUT Time Limit: 1000MS   Memory Limit: 10000K Total Submissions: 9612   Accepted: 62 ...

  4. [bzoj1013][JSOI2008][球形空间产生器sphere] (高斯消元)

    Description 有一个球形空间产生器能够在n维空间中产生一个坚硬的球体.现在,你被困在了这个n维球体中,你只知道球 面上n+1个点的坐标,你需要以最快的速度确定这个n维球体的球心坐标,以便于摧 ...

  5. hihoCoder 1196 高斯消元·二

    Description 一个黑白网格,点一次会改变这个以及与其连通的其他方格的颜色,求最少点击次数使得所有全部变成黑色. Sol 高斯消元解异或方程组. 先建立一个方程组. \(x_i\) 表示这个点 ...

  6. BZOJ 2844 albus就是要第一个出场 ——高斯消元 线性基

    [题目分析] 高斯消元求线性基. 题目本身不难,但是两种维护线性基的方法引起了我的思考. void gauss(){ k=n; F(i,1,n){ F(j,i+1,n) if (a[j]>a[i ...

  7. SPOJ HIGH Highways ——Matrix-Tree定理 高斯消元

    [题目分析] Matrix-Tree定理+高斯消元 求矩阵行列式的值,就可以得到生成树的个数. 至于证明,可以去看Vflea King(炸树狂魔)的博客 [代码] #include <cmath ...

  8. UVALive 7138 The Matrix Revolutions(Matrix-Tree + 高斯消元)(2014 Asia Shanghai Regional Contest)

    题目链接:https://icpcarchive.ecs.baylor.edu/index.php?option=com_onlinejudge&Itemid=8&category=6 ...

  9. [高斯消元] POJ 2345 Central heating

    Central heating Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 614   Accepted: 286 Des ...

随机推荐

  1. javap 反汇编class文件

    用法: javap 参数 class文件路径 其中, 可能的选项包括: -help --help -? 输出此用法消息 -version 版本信息 -v -verbose 输出附加信息 -l 输出行号 ...

  2. python垃圾回收

    python垃圾回收 python垃圾回收主要使用引用计数来跟踪和回收垃圾.在引用计数的基础上,通过“标记—清除”解决容器对象可能产生的循环引用问题,通过“分代回收”以空间换时间的方法提高垃圾回收效率 ...

  3. Spring Boot + Redis

    启动redis docker run --name redisServer -P -d redis redis自带客户端,启动客户端 docker run -it --link redisServer ...

  4. 全网最详细的Hadoop HA集群启动后,两个namenode都是active的解决办法(图文详解)

    不多说,直接上干货! 这个问题,跟 全网最详细的Hadoop HA集群启动后,两个namenode都是standby的解决办法(图文详解) 是大同小异. 欢迎大家,加入我的微信公众号:大数据躺过的坑  ...

  5. JAVA与DOM解析器提高(DOM/SAX/JDOM/DOM4j/XPath) 学习笔记二

    要求 必备知识 JAVA基础知识.XML基础知识. 开发环境 MyEclipse10 资料下载 源码下载   sax.dom是两种对xml文档进行解析的方法(没有具体实现,只是接口),所以只有它们是无 ...

  6. GNU的编译器

    GNU的编译器可以编译C或C++语言, 编译C语言使用gcc,编译C++语言使用g++ 如果是使用Linux或者Unix系统(Mac)可以使用以下命令: gcc -v 或者 g++ -v 来查看是否安 ...

  7. 【K8S学习笔记】Part3:同一Pod中多个容器间使用共享卷进行通信

    本文将展示如何使用共享卷(Volume)来实现相同Pod中的两个容器间通信. 注意:本文针对K8S的版本号为v1.9,其他版本可能会有少许不同. 0x00 准备工作 需要有一个K8S集群,并且配置好了 ...

  8. HTML 框架 frameset,frame

    通过使用框架,你可以在同一个浏览器窗口中显示不止一个页面.每份HTML文档称为一个框架,并且每个框架都独立于其他的框架 框架结构标签(<frameset>) 框架结构标签(<fram ...

  9. 长沙.NET社区之光

    奈何万事开头难 迎着改革开放四十年带来的春风,长沙的互联网生态环境以唐胡子俱乐部为首的一众互联网社群讲长沙互联网的环境推上了一个新的台阶.年底,我与有幸一起共事的溪源兄,下班后一起闲聊,觉着长沙的.N ...

  10. laravel 赋值

    字符串形式: //C层 $res = '123456'; view( ' index/index ' , [ 'v' => $value ] ) ; //V层 原样输出: {$v} 操作: {m ...