TOJ 2690 ZOJ 2849 Attack of Panda Virus / 优先队列+广搜
来源:互联网 发布:吕四洋海难 知乎 编辑:程序博客网 时间:2024/06/01 08:11
Attack of Panda Virus
描述
In recent months, a computer virus spread across networks in China. The virus came with an icon of a lovely panda, hence the name Panda Virus. What makes this virus difficult to handle is that it has many variations.
Unfortunately, our lab's network was also infected with the Panda Virus. As you can see from the above diagram, the computers in our lab are placed in a matrix ofM rows andN columns. A computer is only connected with the computers next to it. At the beginning,T computers were infected with the Panda Virus, each with a different variation (Type 1, Type 2... TypeT). Each computer in the network has a specific defense levelL (0 <L < 1000). The Panda Virus will rapidly spread across the network according to the following rules:
- The virus can only spread along the network from the already infected computers to the clean ones.
- If a computer has already been infected by one virus variation, it will never be infected by another variation.
- The transmission capacity of the Panda Virus will increase each day. In day 1, the virus only infects computers with a defense level 1 provided the virus can spread to that computer, however, a computer with a defense level >1 will stop the transmission along that path. In day D, it can spread to all the computers connected with a defense level <=D, provided that the transmission is not stopped by a computer with a defense level >D along the path.
- Within one day, the virus variation of type 1 would spread first and infects all the computers it can reach. And then the virus variation of type 2, then type 3, etc.
The following samples show the infection process described above:
At the beginning, only 2 computers were infected:
1 0 0 0
0 0 0 2
0 0 0 0
In day 1:
1 0 0 0
0 0 0 2
0 0 2 2
In day 2:
1 0 1 0
1 1 1 2
0 1 2 2
In day 3:
1 1 1 1
1 1 1 2
1 1 2 2
So at last, all the computers in the networks were infected by virus.
Your task is to calculate after all the computers are infected, how many computers are infected with some specific virus variations.
输入
The input contains multiple test cases!
On the first line of each test case are two integersM andN (1 <=M,N <= 500), followed by a M * N matrix. A positive integerT in the matrix indicates that the corresponding computer had already been infected by the virus variations of typeT at the beginning while a negative integer-L indicates that the computer has a defense levelL. Then there is an integerQ indicating the number of queries. Each of the followingQ lines has an integer which is the virus variation type we care.
输出
For each query of the input, output an integer in a single line which indicates the number of computers attacked by this type of virus variation.
样例输入
3 41 -3 -2 -3-2 -1 -2 2-3 -2 -1 -1212
样例输出
93
day不一样的day小的在前 一样的话type小的在前 如果当前点的周围还有没被传染的电脑 你们当前点的day更新到周围level最小的 在进队列
#include <stdio.h>#include <string.h>#include <queue>using namespace std;const int MAX = 510;struct node{int day;int type;int x;int y;bool friend operator < (node a,node b){if(a.day != b.day)return a.day > b.day;return a.type > b.type;}};priority_queue<node> q;int n,m;int cnt[MAX*MAX];int a[MAX][MAX];int dir[4][2] = {0,1,0,-1,1,0,-1,0};void bfs(){int i;while(!q.empty()){int flag = 0;node p = q.top();q.pop();for(i = 0;i < 4; i++){node t;t.x = p.x + dir[i][0];t.y = p.y + dir[i][1];if(t.x >= 1 && t.x <= n && t.y >= 1 && t.y <= m && a[t.x][t.y] < 0){if(p.day >= a[t.x][t.y] * (-1)){t.type = p.type;t.day = p.day;a[t.x][t.y] = p.type;q.push(t);cnt[p.type]++;}else{if(a[t.x][t.y] > flag || !flag)flag = a[t.x][t.y];}}}if(flag){p.day = -flag;q.push(p);}}}int main(){int i,j,k,t;node x;while(scanf("%d %d",&n,&m)!=EOF){while(!q.empty())q.pop();memset(cnt,0,sizeof(cnt));for(i = 1;i <= n; i++){for(j = 1;j <= m; j++){scanf("%d",&a[i][j]);if(a[i][j] > 0){x.x = i;x.y = j;x.type = a[i][j];x.day = 1;cnt[a[i][j]]++;q.push(x);}}}bfs();scanf("%d",&k);while(k--){scanf("%d",&t);printf("%d\n",cnt[t]);}}return 0;}
- TOJ 2690 ZOJ 2849 Attack of Panda Virus / 优先队列+广搜
- ZOJ2849 Attack of Panda Virus 【广搜】【优先队列】
- ZOJ 2849 Attack of Panda Virus(BFS+优先队列)
- 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
- ZOJ2849 Attack of Panda Virus 熊猫烧香~~ 优先队列+搜索
- ZOJ-2849-Attack of Panda Virus【bfs】【优先级队列】【4th浙江省赛】【好题】
- Attack of Panda Virus
- TOJ 1335 HDU 1242 ZOJ 1649 营救天使 / 广搜+优先队列
- zoj2849Attack of Panda Virus
- Dungeon Master ZOJ 1940【优先队列+广搜】
- 广搜+优先队列
- TOJ 2870 ZOJ 3221 Lich / 广搜
- hdu1242 广搜+优先队列
- hdu1026 优先队列+广搜
- 【代码】php 用键名分组相加的二维数组实例函数
- iOS 设备发送推送通知
- WP8页面跳转实现参数传递的多种方法(已完善)
- rvm 使用指南
- 使用Visual Studio快速搭建网站
- TOJ 2690 ZOJ 2849 Attack of Panda Virus / 优先队列+广搜
- 用Gradle 构建你的android程序
- c 指向指针的指针
- 在 linux 下使用 CMake 构建应用程序
- Java运行环境 JRockit
- java学习 知识要点记录1
- sql语句判断 case when用法(二)
- shell程序设计
- mysql不允许远程连接