一、题目

  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. Inkscape 太慢

    问题: 在画板上图像较多时, 会在粘贴 / 删除 时会陷入长时间的等待 解决: 最佳: Ubuntu上面的比windows上的快上几十倍, 测试比较, 感觉并不是Ubuntu上多用了GPU, 总之, ...

  2. VuePress plugins All In One

    VuePress plugins All In One VuePress & element-ui & docs $ yarn add -D vuepress-plugin-demo- ...

  3. Chinese Parents Game

    Chinese Parents Game <中国式家长>是一款模拟养成游戏. 玩家在游戏中扮演一位出生在普通的中式家庭的孩子. https://en.wikipedia.org/wiki/ ...

  4. js operate svg

    js operate svg js dynamic create svg https://stackoverflow.com/questions/20539196/creating-svg-eleme ...

  5. c++ 使用进程id获取打开的网络端口

    #pragma warning( disable : 4996) #include <winsock2.h> #include <ws2tcpip.h> #include &l ...

  6. vue2.0用法以及环境配置

    一.配置环境搭建 1.安装node.js (可以去官网看) 2.安装git (推荐看廖雪峰文章,点击查看) 3.安装vue: cmd:npm install vue //最新稳定版本 npm inst ...

  7. NGK数字钱包的特点是什么?NGK钱包的优点和缺点是什么?

    说起区块链数字资产,那就离不开谈到数字钱包.数字钱包不仅有资产管理的功能,还可以进行资产理财.资产交易,甚至能为公链DAPP导流. 对于NGK公链而言,其数字钱包已然成为了解NGK公链的基础条件.NG ...

  8. c#(winform)获取本地打印机

    引用 using System.Drawing.Printing; //代码 PrintDocument prtdoc = new PrintDocument(); string strDefault ...

  9. Vue和Element基础使用,综合案例学生列表实现

    知识点梳理 课堂讲义 1.Vue 快速入门 1.1.Vue的介绍 Vue是一套构建用户界面的渐进式前端框架. 只关注视图层,并且非常容易学习,还可以很方便的与其它库或已有项目整合. 通过尽可能简单的A ...

  10. Pandas初体验

    目录 Pandas 一.简介 1.安装 2.引用方法 二.series 1.创建方法 2.缺失数据处理 2.1 什么是缺失值 2.2 NaN特性 2.3 填充NaN 2.4 删除NaN 2.5 其他方 ...