ZOJ 2849 Attack of Panda Virus
2016-02-19 20:16
423 查看
题目链接:http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemCode=2849
#include <iostream> #include <queue> #include <set> #include <vector> #include <cstring> #include <algorithm> using namespace std; #define LINE_SIZE 510 int com[LINE_SIZE][LINE_SIZE]; struct Node{ int x; int y; int day; int type; }; bool cmp(Node a, Node b){ return a.type < b.type; } vector<Node> virus; priority_queue<Node> priQue; int type[LINE_SIZE*LINE_SIZE]; bool operator < (const Node a, Node b){ if (a.day != b.day){ return a.day > b.day; } return a.type > b.type; } int movey[4][2] = { { -1, 0 }, { 1, 0 }, { 0, -1 }, { 0, 1 } }; void bfs(){ while (!priQue.empty()){ Node front = priQue.top(); priQue.pop(); int flag = -1e7; for (int aim = 0; aim < 4; aim++){ Node temp; temp.x = front.x + movey[aim][0]; temp.y = front.y + movey[aim][1]; if (com[temp.x][temp.y] < 0){ if (0 - com[temp.x][temp.y] <= front.day){ temp.type = front.type; temp.day = front.day; type[front.type]++; com[temp.x][temp.y] = front.type; priQue.push(temp); } else{ if (flag < com[temp.x][temp.y]) flag = com[temp.x][temp.y]; } } } if (flag != -1e7){ front.day = flag*(-1); priQue.push(front); } } } int main(){ int m, n; while (cin >> m >> n){ memset(com, 0, sizeof(com)); memset(type, 0, sizeof(type)); while (!priQue.empty()){ priQue.pop(); } virus.clear(); for (int i = 1; i <= m; i++){ for (int j = 1; j <= n; j++){ cin >> com[i][j]; if (com[i][j] > 0){ Node temp; temp.x = i; temp.y = j; temp.day = 0; temp.type = com[i][j]; type[com[i][j]]++; virus.push_back(temp); } } } sort(virus.begin(), virus.end(), cmp); for (int i = 0; i < virus.size(); i++){ priQue.push(virus[i]); } bfs(); int Q; cin >> Q; while (Q--){ int nn; cin >> nn; cout << type[nn] << "\n"; } } }
相关文章推荐
- Calculator
- leetcode:Rotate List
- Linux 源码安装Python
- 新手必备的常用代码片段整理(一)
- [Locked] Number of Connected Components in an Undirected Graph
- jsp 界面注册、登录按钮的实现
- IOS 文件系统
- 安卓 自动弹出键盘
- hrbust 1176 小陈老师、雪人【map+优先队列】
- 部署Apache网站服务
- 安卓 单例设计模式 查看方法
- HDU 4602 Partition
- CTeX终于要更新了
- BadUSB的防范研究
- php5.6 源码安装过程
- python 编码问题
- 金额转换,阿拉伯数字转换成中国传统形式。例如:101000001010 转换为 壹仟零壹拾亿零壹仟零壹拾圆整
- 有100个人围成一个圈,从1开始报数,报到14的这个人就要退出, 然后其他人重新开始,从1报数,到14退出。问:最后剩下的是100人中的第几个人?
- markdown学习2:Markdown编辑器之比较
- Java中print、printf、println的区别