HDU3359 Kind of a Blur(高斯消元)
建立方程后消元
#include<cstdio>
#include<iostream>
#include<cstdlib>
#include<cstring>
#include<string>
#include<algorithm>
#include<map>
#include<queue>
#include<vector>
#include<cmath>
#include<utility>
using namespace std;
typedef long long LL;
const int N = 108, INF = 0x3F3F3F3F;
const double eps = 1e-8;
double f[N][N];
bool inf[N]; template<typename T>
void gauss_jordan(T A[N][N], int n){
for(int i = 0; i < n; i++){
//选择一行r与第i行交换
int r = i;
for(int j = i + 1; j < n; j++){
if(abs(A[j][i]) > abs(A[r][i])){
r = j;
}
}
if(abs(A[r][i]) < eps){
continue;
}
if(r != i){
for(int j = 0; j <= n; j++){
swap(A[r][j], A[i][j]);
}
}
for(int k = 0; k < n; k++){
if(k != i){
for(int j = n; j >= i; j--){
A[k][j] -= A[k][i] / A[i][i] * A[i][j];
}
}
}
}
} int main(){
bool flag = 0;
int h, w, d;
while(scanf("%d %d %d", &w, &h, &d), w || h || d){
memset(f, 0, sizeof(f));
for(int i = 0; i < h; i++){
for(int j = 0; j < w; j++){
double t;
scanf("%lf", &t);
int u = i * w + j;
f[u][w * h] = t;
int cnt = 0;
for(int x = max(0, i - d) ; x <= min(h - 1, i + d); x++){
for(int y = max(0, j - d) ; y <= min(w - 1, j + d); y++){
if(abs(x - i) + abs(y - j) <= d){
cnt ++;
}
}
} for(int x = max(0, i - d) ; x <= min(h - 1, i + d); x++){
for(int y = max(0, j - d) ; y <= min(w - 1, j + d); y++){
if(abs(x - i) + abs(y - j) <= d){
int v = x * w + y;
f[u][v] = 1.0 / (double)cnt;
}
}
}
}
}
gauss_jordan(f, w * h);
if(flag){
printf("\n");
}
flag = 1;
for(int i = 0; i < h; i++){
for(int j = 0; j < w; j++){
printf("%8.2f", f[i * w + j][w * h] / f[i * w + j][i * w + j]);
}
printf("\n");
} }
return 0;
}
HDU3359 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 ...
- HDU3359(SummerTrainingDay05-I 高斯消元)
Kind of a Blur Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)To ...
- HDU_3359 Kind of a Blur 【浮点型高斯消元+BFS】
一.题目 Kind of a Blur 二.分析 题目读起来挺费劲的. 主要就是要求一个矩阵,其中每个点及其于这个的曼哈顿距离小于D的点的值总和的平均值就是新生成的矩阵. 给定新生成的矩阵,求初始矩阵 ...
- 【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\) 表示这个点 ...
随机推荐
- getopt函数的使用——分析命令行参数
getopt(分析命令行参数) getopt(分析命令行参数) 短参数的定义 返回值 范例 getopt_long 相关函数表头文件#include<unistd.h> 函数声明int g ...
- PHP判断用户操作系统(Android,ipad,iphone,windows)
这段脚本可以运用在:针对不同的操作系统,把用户引导向相应的网站或做相应的处理. <?php // PHP 判断客户端平台(PC.安卓.iPhone.平板) // strpos() 函数返回字符串 ...
- $_request,$post,$get的三者区别和特点
一.$_request与$_post.$_get的区别和特点 $_REQUEST[]具用$_POST[] $_GET[]的功能,但是$_REQUEST[]比较慢.通过post和get方法提交的所有数据 ...
- [转]Mysql海量数据存储和解决方案之一—分布式DB方案
1) 分布式DB水平切分中用到的主要关键技术:分库,分表,M-S,集群,负载均衡 2) 需求分析:一个大型互联网应用每天几十亿的PV对DB造成了相当高的负载,对系统的稳定性的扩展性带来极大挑战. 3 ...
- VQuery高级特性
VQuery高级特性 css方法 同时设置多个--for in 链式操作 链式操作 函数,链式操作 css 方法链式操作 json的使用 阻止冒泡,默认事件 VQuery插件 插件机制 可以扩展库的功 ...
- Zebra_Form Packages: Zebra_Form Controls Generic XSS_Clean Classes: Zebra_Form_Control Class: Zebra_Form_Control
http://stefangabos.ro/wp-content/docs/Zebra_Form/Generic/Zebra_Form_Control.html#methodset_rule
- C语言中#define的用法(转)
转自:http://www.dingge.com/main/article.asp?id=10 今天整理了一些#define的用法,与大家共享! 1.简单的define定义 #define MAXTI ...
- ls常用选项总结
参考: http://billie66.github.io/TLCL/book/index.html ls - List directory contents 选项 长选项 描述 -a --all 列 ...
- centos 7 升级后yum install出现Exiting on user cancel
centos 7 升级后yum install出现Exiting on user cancel centos 7.x升级后用yum install进行安装时经常出现Exiting on user ca ...
- Android webView解析URL参数
2015年6月18日 13:56:21 星期四 又当爹又当娘啊............ public void onPageFinished(WebView view, String url) { s ...