ZOJ--2849 Attack of Panda Virus
来源:互联网 发布:python最好的教材 编辑:程序博客网 时间:2024/06/07 02:23
在一个电脑网络中有n*m台电脑,网络中有病毒,标号为正数,负数则表示该电脑最早可以被感染病毒的天数。标号小的病毒先感染。求最后各个病毒都感染了多少台电脑。
http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemId=1849
搜索。用一个优先队列。优先队列里面存储坐标、被感染的病毒编号和第几天被感染。
优先选取先感染的点,若感染的时间一样,就选取病毒标号小的点。
#include <queue>#include <stack>#include <cstdio>#include <vector>#include <cstring>#include <iostream>#include <algorithm>using namespace std;#define pb push_back#define MP make_pairtypedef long long ll;const int inf = 0x3f3f3f3f;const int mod = 1000000007;const int maxn = 510;int dxy[4][2] = { {1, 0}, {0, 1}, {-1, 0}, {0, -1} };struct HeapNode{ int x, y, type, day; HeapNode(){} HeapNode(int _x, int _y, int _type, int _day):x(_x), y(_y), type(_type), day(_day){ } bool operator < (const HeapNode& t) const{ return (day > t.day) || (day == t.day && type > t.type); }};int a[maxn][maxn], vis[maxn][maxn], ans[maxn * maxn], t[maxn][maxn];int n, m, q;int main(){ while(scanf("%d%d", &n, &m) == 2){ memset(vis, 0x3f, sizeof(vis)); memset(ans, 0, sizeof(ans)); memset(t, 0x3f, sizeof(t)); priority_queue<HeapNode> Q; while(!Q.empty()) Q.pop(); for(int i=0; i<n; i++){ for(int j=0; j<m; j++){ scanf("%d", &a[i][j]); if(a[i][j] > 0){ Q.push(HeapNode(i, j, a[i][j], 0)); vis[i][j] = a[i][j]; t[i][j] = 0; } } } while(!Q.empty()){ HeapNode now = Q.top(); Q.pop(); if(a[now.x][now.y] < 0 && (vis[now.x][now.y] < now.type || t[now.x][now.y] < now.day)) continue;//若该点已被其他标号更小的病毒感染 for(int i=0; i<4; i++){ int xx = now.x + dxy[i][0]; int yy = now.y + dxy[i][1]; if(xx < 0 || xx >= n || yy < 0 || yy >= m || a[xx][yy] > 0) continue; int d = max(-a[xx][yy], now.day);//若被当前点感染的感染天数 if(t[xx][yy] < d) continue; if(t[xx][yy] == d){ if(vis[xx][yy] <= now.type) continue; vis[xx][yy] = now.type; Q.push(HeapNode(xx, yy, now.type, d)); } else{ t[xx][yy] = d; vis[xx][yy] = now.type; Q.push(HeapNode(xx, yy, now.type, d)); } } } for(int i=0; i<n; i++) for(int j=0; j<m; j++) ans[ vis[i][j] ]++; scanf("%d", &q); int x; while(q--){ scanf("%d", &x); printf("%d\n", ans[x]); } } return 0;}
0 0
- ZOJ 2849 Attack of Panda Virus
- zoj 2849 Attack of Panda Virus
- ZOJ--2849 Attack of Panda Virus
- ZOJ 2849Attack of Panda Virus
- ZOJ 2849 Attack of Panda Virus
- ZOJ 2849 Attack of Panda Virus(BFS+优先队列)
- Attack of Panda Virus
- TOJ 2690 ZOJ 2849 Attack of Panda Virus / 优先队列+广搜
- ZOJ-2849-Attack of Panda Virus【bfs】【优先级队列】【4th浙江省赛】【好题】
- ZOJ2849 Attack of Panda Virus 熊猫烧香~~ 优先队列+搜索
- ZOJ2849 Attack of Panda Virus 【广搜】【优先队列】
- zoj2849Attack of Panda Virus
- computer virus attack
- ZOJ 2587 Unique Attack
- zoj 3573 Under Attack
- zoj 3573 Under Attack
- ZOJ 2587 Unique Attack
- zoj 3573 Under Attack
- 关于C++类成员函数的重载、覆盖、隐藏与virtual关键字
- [重要]使用Vitamio打造自己的Android万能播放器(10)—— 本地播放 (缩略图、视频信息、视频扫描服务)
- Java异常的栈轨迹(Stack Trace)
- MFC+OPENCV摄像机标定
- 一些软件设计的原则
- ZOJ--2849 Attack of Panda Virus
- android手机应用开发(一)
- centos最新软件源镜像站点大全
- cdoj 方师傅与01串(二叉树)
- linux内核学习资料收集
- 【读书笔记】代码整洁之道 第2章有意义的命名
- Linux用户管理
- Exercice_3.8
- 使用Vitamio打造自己的Android万能播放器(11)—— 本地扫描后台服务