NYOJ InterestingPunch-Bowl
来源:互联网 发布:政府网络不能玩皮皮 编辑:程序博客网 时间:2024/06/05 22:41
Dr.Kong has taken a side job designing interesting punch-bowl designs. The designs are created as follows:
* A flat board of size W cm * H cm is procured (3 <= W <= 300, 3 <= H <= 300)
* On every 1 cm x 1 cm square of the board, a 1 cm x 1 cm block is placed. This block has some integer height B (1 <= B <= 1,000,000,000)
The blocks are all glued together carefully so that punch will not drain through them. They are glued so well, in fact, that the corner blocks really don't matter!
Dr.Kong can never figure out, however, just how much punch their bowl designs will hold. Presuming the bowl is freestanding (i.e., no special walls around the bowl), calculate how much juice the bowl can hold. Some juice bowls, of course, leak out all the juice on the edges and will hold 0.
Input
* Lines 2..H+1: Line i+1 contains row i of bowl heights: W space-separated integers each of which represents the height B of a square in the bowl. The first integer is the height of column 1, the second integers is the height of column 2, and so on.
There are several test cases and end with the end of the file.
Output
Sample Input
4 5 5 8 7 75 2 1 57 1 7 18 9 6 99 8 9 9
Sample Output
12
题意:一个N*M的“碗“,数字对应位置有一个高度的柱子,然后如果往里面无限加水,最多会存下多少水。
分析:一个位置能存下多少水是由四周最低的柱子高度决定的,所以我们先从碗一圈的位置高度存起来,然后找出最低的,推出四周四个位置的水高度,如果发现高度比本位置低的就说明次位置最多能存的水,比本位置高的说明存不下水。 然后把这些位置和最高高度存下来,然后重复就GG。
代码:
#include <bits/stdc++.h>using namespace std;int Map[305][305],n,m;;struct node{ int x,y,v;};struct cmp{ int operator()(node x,node y){ return x.v>y.v; }};priority_queue<node,vector<node>,cmp>q;void solve(){ int vis[305][305]; long long ans=0; memset(vis,0,sizeof(vis)); int move[4][2]={0,1 ,1,0 ,0,-1 ,-1,0}; while(!q.empty()){ node now=q.top(); // printf("%d %d %d\n",now.x,now.y,now.v); q.pop(); vis[now.x][now.y]=1; for(int i=0;i<4;i++){ node next; next.x=now.x+move[i][0]; next.y=now.y+move[i][1]; next.v=Map[next.x][next.y]; if(next.x<=0 || next.y<=0 || next.x>n || next.y>m || vis[next.x][next.y])continue; if(Map[next.x][next.y]<Map[now.x][now.y]){ ans+=Map[now.x][now.y]-Map[next.x][next.y]; Map[next.x][next.y]=Map[now.x][now.y]; next.v=now.v; } vis[next.x][next.y]=1; q.push(next); } } printf("%lld\n",ans);}int main(){ while(~scanf("%d%d",&m,&n)){ while(!q.empty())q.pop(); for(int i=1;i<=n;i++){ for(int j=1;j<=m;j++){ scanf("%d",&Map[i][j]); node t; t.x=i;t.y=j;t.v=Map[i][j]; if(i==1 || j==1 || i==n || j==m)q.push(t); } } solve(); }}
- NYOJ InterestingPunch-Bowl
- buy super bowl jerseys
- cheap super bowl jersey
- POJ 1076 Bowl 笔记
- 有关GOLDEN Bowl 的思考
- cheap super bowl XLIX jerseys
- where to buy super bowl jerseys
- Data Science Bowl 2017数据预处理
- Cheap nfl super bowl jerseys wholesale from china
- An Egghead’s Guide to the Super Bowl
- Vikings DE Danielle Hunter’s goals: starting lineup, Pro Bowl
- NYOJ
- NYOJ
- NYOJ
- NYOJ
- NYOJ
- NYOJ
- NYOJ
- 更好的 SQL 模式的 10 条规则
- http和https有什么区别?
- 单例模式
- bzoj2957 楼房重建
- 半自动化生成README.md文件
- NYOJ InterestingPunch-Bowl
- 我的博客之路---起点
- Linux--01--WEB服务器安装
- 图像处理中的形态学(二)
- Python 3 安装 BeautifulSoup
- java8新特性之函数式接口、lambda表达式、接口的默认方法、方法和构造函数的引用
- HDU
- Leetcode 72. Edit Distance
- 数论