一、题目

  Kind of a Blur

二、分析

  题目读起来挺费劲的。

  主要就是要求一个矩阵,其中每个点及其于这个的曼哈顿距离小于D的点的值总和的平均值就是新生成的矩阵。

  给定新生成的矩阵,求初始矩阵。

  相当于就是一个点的值与多个点的值相关联,那么列一个(WH)列,(WH)个未知数的方程组,然后解方程就可以了,由于值是浮点型,那么就是浮点型的高斯消元。

三、AC代码

#include <bits/stdc++.h>

using namespace std;
#define ll long long
#define Min(a,b) ((a)>(b)?(b):(a))
#define Max(a,b) ((a)>(b)?(a):(b)) const int maxn = 2e2 + 20;
const double eps = 1e-7;
int W, H, D;
double M[20][20]; class GaussMatrix
{
public:
double a[maxn][maxn];
int equ, val; //行数、列数
void swapRow(int rowOne, int rowTwo)
{
for(int i = 1; i <= val; ++i)
{
swap(a[rowOne][i], a[rowTwo][i]);
}
}
void swapCol(int colOne, int colTwo)
{
for(int i = 1; i <= equ; ++i)
{
swap(a[i][colOne], a[i][colTwo]);
}
}
bool same(double x, double y)
{
return fabs(x - y) < eps;
}
int guass()
{
int k, col;
for(k = 1, col = 1; k <= equ && col < val; k++, col++)
{
//找到[k, equ]行中,col列值最大的行
int maxRow = k;
for(int i = k + 1; i <= equ; i++)
{
if(fabs(a[i][col]) > fabs(a[maxRow][col]))
{
maxRow = i;
}
}
//如果col列都为0,直接处理下一列
if(same(a[maxRow][col], 0))
{
--k;
continue;
}
if(maxRow != k)
swapRow(k, maxRow);
//约掉最上面这行约数,是当前行第col列第一个数系数为1
for(int i = col + 1; i <= val; i++)
{
a[k][i] /= a[k][col];
}
a[k][col] = 1.0;
//消元
//1*x + b*y + c*z = d1
//a2*x + b2*y + c2*z = d2
//a3*x + b3*y + c3*z = d3
for(int i = 1; i <= equ; i++)
{
if(i == k)
continue;
for(int j = col + 1; j <= val; j++)
{
a[i][j] -= a[i][col]*a[k][j];
}
a[i][col] = 0.0;
}
}
//扫描一下剩下的行,如果有解,则应全部都被消为了0
for(k; k <= equ; k++)
{
if(!same(a[k][val], 0))
return -1;
}
return val - k;
}
}arr; struct node
{
int x, y, len;
node(int a, int b, int l)
{
x = a, y = b;
len = l;
}
};
bool visited[20][20];
const int dx[] = {0, -1, 0, 1};
const int dy[] = {1, 0, -1, 0}; int toHash(int i, int j)
{
return (i-1)*W + j;
} bool judge(int x, int y)
{
if( !visited[x][y] && x > 0 && x <= H && y > 0 && y <= W)
return true;
return false;
} void init(int x, int y, int row)
{
memset(visited, 0, sizeof(visited));
queue<node> que;
memset(visited, 0, sizeof(visited));
que.push(node(x, y, 0));
int has = 0;
while(!que.empty())
{
node t = que.front();
que.pop();
if(t.len <= D && judge(t.x, t.y))
{
arr.a[row][toHash(t.x, t.y)] = 1.0;
has++;
for(int i = 0; i < 4; i++)
{
que.push(node(t.x+dx[i], t.y+dy[i], t.len+1));
}
}
visited[t.x][t.y] = 1;
}
arr.a[row][W*H+1] = M[x][y]*has;
} void solve()
{
int cnt = 0;
arr.equ = W*H;
arr.val = W*H + 1;
memset(arr.a, 0, sizeof(arr.a));
for(int i = 1; i <= H; i++)
{
for(int j = 1; j <= W; j++)
{
init(i, j, ++cnt);
}
}
arr.guass();
int to = 1;
for(int i = 1; i <= H; i++)
{
for(int j = 1; j <= W; j++)
{
printf("%8.2lf", arr.a[to++][W*H+1]);
}
printf("\n");
}
} int main()
{
//freopen("input.txt", "r", stdin);
bool flag = 0;
while(scanf("%d%d%d", &W, &H, &D) != EOF)
{
if( !(W+H+D) )
break;
if(flag)
puts("");
else
flag = 1;
for(int i = 1; i <= H; i++)
{
for(int j = 1; j <= W; j++)
{
scanf("%lf", &M[i][j]);
}
}
solve();
}
return 0;
}

HDU_3359 Kind of a Blur 【浮点型高斯消元+BFS】的更多相关文章

  1. 期望dp+高斯消元+bfs——hdu4418

    高斯消元又弄了半天.. 注意只要能建立矩阵,那就必定有解,所以高斯消元里可以直接return 1 #include<bits/stdc++.h> using namespace std; ...

  2. hdu 3359 Kind of a Blur (高斯消元 浮点型)

    题目链接 题意: H * W (W,H <= 10) 的矩阵A的某个元素A[i][j],从它出发到其他点的曼哈顿距离小于等于D的所有值的和S[i][j]除上可达点的数目,构成了矩阵B.给定矩阵B ...

  3. HDU 3359 Kind of a Blur(高斯消元)

    题意: H * W (W,H <= 10) 的矩阵A的某个元素A[i][j],从它出发到其他点的曼哈顿距离小于等于D的所有值的和S[i][j]除上可达点的数目,构成了矩阵B.给定矩阵B,求矩阵A ...

  4. HDU3359(SummerTrainingDay05-I 高斯消元)

    Kind of a Blur Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)To ...

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

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

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

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

  7. *POJ 1222 高斯消元

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

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

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

  9. hihoCoder 1196 高斯消元·二

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

随机推荐

  1. woj1013 Barcelet 字符串 woj1014 Doraemon's Flashlight 几何

    title: woj1013 Barcelet 字符串 date: 2020-03-18 18:00:00 categories: acm tags: [acm,字符串,woj] 字符串,字典序. 1 ...

  2. bochs 调试 com 文件 magicbreak

    参考 https://blog.csdn.net/housansan/article/details/41833581 在网上看到2中解决此问题的方法:1.使用dos下的debug32工具单步跟踪pm ...

  3. 【原】无脑操作:Centos 7.6 + MariaDB + Rsyslog + LogAnalyzer环境搭建

    背景: 网络安全法第三章第二十一条明确规定"采取监测.记录网络运行状态.网络安全事件的技术措施,并按照规定留存相关的网络日志不少于六个月". 为了满足合规性的要求,应当建设相应的日 ...

  4. Lenet车牌号字符识别+保存模型

    # 部分函数请参考前一篇或后一篇文章 import tensorflow as tf import tfrecords2array import numpy as np import matplotl ...

  5. Web API 设计

    Web API 设计 The Design of Web APIs free online ebook https://www.manning.com/books/the-design-of-web- ...

  6. Google Developer Days 2019 & GDD

    Google Developer Days 2019 2019 Google 开发者大会 GDD Google Developer Days https://events.google.cn/intl ...

  7. React Hooks vs React Class vs React Function All In One

    React Hooks vs React Class vs React Function All In One React Component Types React Hooks Component ...

  8. 「NGK每日快讯」2021.1.14日NGK公链第72期官方快讯!

  9. spring框架aop用注解形式注入Aspect切面无效的问题解决

    由于到最后我的项目还是有个邪门的错没解决,所以先把文章大概内容告知: 1.spring框架aop注解扫描默认是关闭的,得手动开启. 2.关于Con't call commit when autocom ...

  10. Spring Security 实战干货:OAuth2登录获取Token的核心逻辑

    1. 前言 在上一篇Spring Security 实战干货:OAuth2授权回调的核心认证流程中,我们讲了当第三方同意授权后会调用redirectUri发送回执给我们的服务器.我们的服务器拿到一个中 ...