HDU3359(SummerTrainingDay05-I 高斯消元)
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
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
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
Sample Input
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
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
//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 高斯消元)的更多相关文章
- 【BZOJ-3143】游走 高斯消元 + 概率期望
3143: [Hnoi2013]游走 Time Limit: 10 Sec Memory Limit: 128 MBSubmit: 2264 Solved: 987[Submit][Status] ...
- 【BZOJ-3270】博物馆 高斯消元 + 概率期望
3270: 博物馆 Time Limit: 30 Sec Memory Limit: 128 MBSubmit: 292 Solved: 158[Submit][Status][Discuss] ...
- *POJ 1222 高斯消元
EXTENDED LIGHTS OUT Time Limit: 1000MS Memory Limit: 10000K Total Submissions: 9612 Accepted: 62 ...
- [bzoj1013][JSOI2008][球形空间产生器sphere] (高斯消元)
Description 有一个球形空间产生器能够在n维空间中产生一个坚硬的球体.现在,你被困在了这个n维球体中,你只知道球 面上n+1个点的坐标,你需要以最快的速度确定这个n维球体的球心坐标,以便于摧 ...
- hihoCoder 1196 高斯消元·二
Description 一个黑白网格,点一次会改变这个以及与其连通的其他方格的颜色,求最少点击次数使得所有全部变成黑色. Sol 高斯消元解异或方程组. 先建立一个方程组. \(x_i\) 表示这个点 ...
- BZOJ 2844 albus就是要第一个出场 ——高斯消元 线性基
[题目分析] 高斯消元求线性基. 题目本身不难,但是两种维护线性基的方法引起了我的思考. void gauss(){ k=n; F(i,1,n){ F(j,i+1,n) if (a[j]>a[i ...
- SPOJ HIGH Highways ——Matrix-Tree定理 高斯消元
[题目分析] Matrix-Tree定理+高斯消元 求矩阵行列式的值,就可以得到生成树的个数. 至于证明,可以去看Vflea King(炸树狂魔)的博客 [代码] #include <cmath ...
- 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 ...
- [高斯消元] POJ 2345 Central heating
Central heating Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 614 Accepted: 286 Des ...
随机推荐
- Git-遇到的问题以及解决方法
1.将本地内容推送到远程仓库后,远程仓库里的文件夹不可点击 原因:在本地添加文件夹A时,又在A里使用了git init命令 解决:删除文件夹A,再重新添加过 2.其他人推送不了内容到远程仓库 原因:权 ...
- 关于SQL的常用操作(增、删、改、查)
关于SQL的常见操作主要是增.删.改.查. 1.增,顾名思义就是新增数据(insert into).该语句用于向表中插入新纪录.insert into有两种用法. (1).无需指定要插入数据的列名,只 ...
- ss的使用配置(电脑、手机FQ)
注:FQ仅用于google查阅资料等,禁止违规违法行为 自己搭建ss服务 1.vps购买:https://www.alpharacks.com/holiday 按流程填完相关信息(Operating ...
- Nginx安装使用及与tomcat实现负载均衡
1. 背景 基于nginx强大的功能,实现一种负载均衡,或是不停机更新程序等.nginx相比大家基本上都知道是什么来头了,具体的文章大家可以去搜索相关文章学习阅读,或是可以查看Nginx中文文档和Ng ...
- 给1~3年iOS开发 经验朋友们的一些建议(附BAT面试题)
前言 由于笔者是做 iOS 开发的,因此本文也仅对做 iOS 的同行们有针对性,其他方向仅供参考. 1,如果你: 1~3年左右工作经验,本科,非计算机相关科班出生,学校又比较一般. 实习企业不理想没有 ...
- 线程中的读写锁ReadWriteLock
Lock锁还有两个非常强大的类 ReadWriteLock接口实现类ReentrantReadWriteLock(非常重要的锁) 想实现 读取的时候允许多线程并发访问,写入的时候不允许. 这种效果.. ...
- gvim配置相关
用 vundle 来管理 vim 插件(包含配置文件vimrc和gvimrc) gvim插件管理神器:vundle的安装与使用 Vim插件管理Vundle Linux 下VIM的配置 Vim配置系列( ...
- C# 字符串操作基本过程(Equals、Compare、EndsWith等处理方法)
本文只介绍了比较方法,但是EndsWith,IndexOf等方法均采用相同的过程,先设置CultureInfo(一般情况下调用当前线程的CultureInfo,该语言文化可以通过控制面板设置),然后调 ...
- Android的几种弹出框
项目效果图: 新建一个项目,结构图如下所示: activity_main.xml: <?xml version="1.0" encoding="utf-8" ...
- volatile双重检查锁定与延迟初始化
一.基本概念: 1.volatile是轻量级的synchronized,在多核处理器开发中保证了共享变量的“可见性”.可见性的意思是,当一个线程修改一个共享变量时,另一个线程能读到这个修改的值. 2. ...