栏目分类:
子分类:
返回
名师互学网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
名师互学网 > IT > 面试经验 > 面试问答

poj 2227 The Wedding Juicer

面试问答 更新时间: 发布时间: IT归档 最新发布 模块sitemap 名妆网 法律咨询 聚返吧 英语巴士网 伯小乐 网商动力

poj 2227 The Wedding Juicer

#include<cstdio>#include<cstring>#include<algorithm>#include<queue>using namespace std;int r,c;typedef long long ll;ll map[400][400];struct Data{    int x,y;    ll h;    bool operator<(const Data ≠)const    {        return h>ne.h;    }    Data(){};    Data(int _x,int _y,ll _h)    {        x=_x;        y=_y;        h=_h;    }};priority_queue<Data> Q;int dr[][2]={0,1,0,-1,1,0,-1,0};bool in(int x,int y){    return x>=1&&x<=r&&y>=1&&y<=c;}int main(){    while(scanf("%d%d",&c,&r)!=EOF)    {        for(int i=1;i<=r;i++)        { for(int j=1;j<=c;j++) {     scanf("%lld",&map[i][j]); }        }        while(!Q.empty()) Q.pop();        for(int i=1;i<=r;i++)        { Q.push(Data(i,1,map[i][1])); Q.push(Data(i,c,map[i][c])); map[i][1]=-1; map[i][c]=-1;        }        for(int i=1;i<=c;i++)        { Q.push(Data(1,i,map[1][i])); Q.push(Data(r,i,map[r][i])); map[1][i]=-1; map[r][i]=-1;        }        long long ans=0;        while(!Q.empty())        { Data a=Q.top(),b; Q.pop(); for(int i=0;i<4;i++) {     b.x=a.x+dr[i][0];     b.y=a.y+dr[i][1];     if(in(b.x,b.y))     {         ll tp=map[b.x][b.y];         if(tp==-1)  continue;         else if(tp<a.h)         {  ans+=a.h-tp;         }         b.h=max(tp,a.h);         Q.push(b);         map[b.x][b.y]=-1;     } }        }        printf("%lldn",ans);    }    return 0;}
转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/it/371588.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 (c)2021-2022 MSHXW.COM

ICP备案号:晋ICP备2021003244-6号