Pool in minecraft
来源:互联网 发布:平面设计软件cdr 编辑:程序博客网 时间:2024/03/28 23:47
Description
在宇宙的另一边有个很奇怪的世界,我们称它为minecraft,在minecraft星球物体并不是由原子构成的,也不是由夸克组成的,而是由“方块”拼成的,不管你信不信,反正我是信了。来自minecraft的Mr.P在他家建造了一些储水池,该储水池全部都是由1x1x1的立方体拼成的,下图是Mr.P在微博上晒的一张图片。
为了方便地球人理解,Mr.P用N*N的矩阵对水池进行描述,其中的数字表示对应位置的高度。
Mr.P想问你他家的储水池最多能存多少体积的水?
Input
首先一个整数T,表示数据组数。(不超过25组,其中90%为小数据)
下面每组数据第一行是一个整数N(3≤N≤1000),表示矩阵规模为N*N。
接下来N行,每行N个整数,表示对应位置高度h(0≤h≤1000)。
Output
每组数据输出一行,Mr.P想问你的那个整数。
Sample Input
270 0 1 1 1 0 00 1 0 0 0 1 01 0 0 1 0 0 11 0 1 3 1 0 11 0 0 1 0 0 10 1 0 0 0 1 00 0 1 1 1 0 071 1 1 1 1 1 11 0 0 0 0 0 11 0 3 3 3 0 11 0 3 2 3 0 11 0 3 3 3 0 11 0 0 0 0 0 11 1 1 1 1 1 1
Sample Output
1617
HINT
感觉思路略神奇,看了题解仍感觉没有充分理解,日后再来做做。
思路:bfs的思想,采用优先队列先将外围的点入队,然后总是寻找最低的点,计算高度差,具体见代码。
#include<iostream>#include<stdio.h>#include<algorithm>#include<queue>using namespace std;int dx[4]={0,1,0,-1};int dy[4]={1,0,-1,0};int m[1010][1010];struct node{int x;int y;int h;bool operator < (const node &rhs) const {return h > rhs.h ;}node(int x=0,int y=0, int h=0) : x(x) ,y(y), h(h) {}};int main(){int n,T;scanf("%d",&T);while(T--){scanf("%d",&n);for(int i=1;i<=n;i++)for(int j=1;j<=n;j++)scanf("%d",&m[i][j]);priority_queue <node> q;for(int i=2;i<n;i++){q.push(node(1,i,m[1][i]));m[1][i]=-1;q.push(node(n,i,m[n][i]));m[n][i]=-1;q.push(node(i,1,m[i][1]));m[i][1]=-1;q.push(node(i,n,m[i][n]));m[i][n]=-1;}m[1][1]=-1;m[1][n]=-1;m[n][1]=-1;m[n][n]=-1;int h=0,ans=0; while(!q.empty()){node a=q.top();q.pop();if(a.h<h)ans+=h-a.h;h=max(h,a.h);for(int i=0;i<=3;i++){int xx=a.x+dx[i];int yy=a.y+dy[i];if(xx>=1&&xx<=n&&yy>=1&&yy<=n&&m[xx][yy]>=0){q.push(node(xx,yy,m[xx][yy]));m[xx][yy]=-1;}}}printf("%d\n",ans);}return 0}
0 0
- Pool in minecraft
- CSU 1672 Pool in minecraft
- Minecraft
- Minecraft
- Connection Pool in RESIN
- STRING POOL IN JAVA
- [原创] Build a thread pool in C
- pool memory allocate in SGI STL
- Build a thread pool in C
- Exception in BPOfferService for Block pool BP
- ClassFormatException: Invalid byte tag in constant pool
- java.lang.IllegalStateException: Already in the pool!
- Exception in thread “commons-pool-EvictionTimer”
- First Module Pool Program in SAP
- ClassFormatException Invalid byte tag in constant pool
- Invalid byte tag in constant pool: 15
- Invalid byte tag in constant pool 15
- POOL
- 安装eclipse maven插件m2eclipse
- [易飞]信息传递-多表(含外表)关联取值
- BPC编码公开了
- 数学建模四类基本模型
- android 自定义水平和圆形progressbar 只定义一些style就可以
- Pool in minecraft
- GIT常用命令
- mysql参数之slave_skip_errors
- Java泛型-类型擦除
- Android之手机闹钟
- 【CCF】找相反数
- springmvc中url-url-pattern /和/*的区别
- HEAP CORRUPTION DETECTED
- 设计模式:13 建造者模式