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

zoj 2849 Attack of Panda Virus

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

zoj 2849 Attack of Panda Virus

#include<stdio.h>#include<string.h>#include<algorithm>#include<queue>#include<vector>#include<iostream>using namespace std;const int M = 1000000000;struct PP{ int type,day;}dp[501][501];struct p{ int x,y,type,day;}fr,o,st[501*501];int cmp1(p A,p B){ return A.type<B.type; }int g[501][501],res[501*501],c[4][2]={1,0,0,1,-1,0,0,-1},m,n;bool operator<(const p& A,const p& B){ return A.day>B.day;}priority_queue<p>q;void bfs(){ int i; while(!q.empty()) { fr=q.top(); q.pop(); for(i=0;i<4;i++) { o=fr; o.x=fr.x+c[i][0]; o.y=fr.y+c[i][1]; if(o.x>=0&&o.y>=0&&o.x<m&&o.y<n&&g[o.x][o.y]<0) { if(o.day<-g[o.x][o.y])o.day=-g[o.x][o.y]; if(dp[o.x][o.y].day>o.day) { dp[o.x][o.y].type=o.type; dp[o.x][o.y].day=o.day; q.push(o);  }  else if(dp[o.x][o.y].day==o.day&&dp[o.x][o.y].type>o.type) { dp[o.x][o.y].type=o.type; q.push(o);  }  }  } } }int main(){ int i,j,k; while(~scanf("%d%d",&m,&n)) { for(i=0;i<m;i++) for(j=0;j<n;j++) { dp[i][j].day=M;  } k=0; for(i=0;i<m;i++) for(j=0;j<n;j++) { scanf("%d",&g[i][j]); if(g[i][j]>0) { st[k].x=i; st[k].y=j; st[k].day=1; st[k].type=g[i][j]; dp[i][j].type=g[i][j]; dp[i][j].day=1; k++;  }  } while(!q.empty())q.pop();  for(i=0;i<k;i++) { q.push(st[i]);  } bfs(); memset(res,0,sizeof(res)); for(i=0;i<m;i++) for(j=0;j<n;j++) res[dp[i][j].type]++; scanf("%d",&m); while(m--) { scanf("%d",&i); printf("%dn",res[i]);  }  }}
转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/it/373300.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

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

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