多校第四场 1010 hdu 5336 XYZ and Drops(bfs+模拟)
2015-07-31 14:25
423 查看
题目链接:
hdu 5336题目大意:
给出一个r*m的棋盘,给出一个初始的要爆炸的水滴,和一些静止的大小不会超过4的水滴,当水滴大小超过4的时候会爆炸,爆炸之后又水滴的位置可以继续走,每个水滴爆炸变成四股水流,可以与水滴交汇,导致水滴的大小加1,水流消失。问给定时间内水滴爆炸的时间,和没爆炸的水滴的大小题目分析:
我们可以用队列存放的状态,然后按照提议利用bfs进行模拟,然后标记某个水滴当前的大小和时候已经爆炸过以及爆炸的时间,直接模拟就好,姿势好的话几十行代码就搞定了。AC代码:
#include <iostream> #include <cstring> #include <algorithm> #include <cstdio> #include <queue> #define MAX 107 using namespace std; int r,c,n,t,x,y; int mp[MAX][MAX]; int mark[MAX][MAX]; int rx[MAX]; int ry[MAX]; int dx[]={0,1,0,-1}; int dy[]={1,0,-1,0}; struct Node { int x,y,d,t; Node ( int a , int b , int c , int e ) { x = a; y = b; d = c; t = e; } }; void solve ( ) { mp[x][y] = 4; queue<Node> q; q.push ( Node ( x , y , 0 , 0 )); while (!q.empty()) { int tx = q.front().x; int ty = q.front().y; int td = q.front().d; int tt = q.front().t; q.pop(); if (tt > t ) break; if ( 0< mp[tx][ty] && mp[tx][ty] < 5 || mark[tx][ty]==tt) { mp[tx][ty]++; if ( mp[tx][ty] == 5 ) { mark[tx][ty] = tt; for ( int i = 0 ; i < 4 ; i++ ) { int u = tx+dx[i] , v = ty + dy[i]; if ( u <= 0 || v <= 0 || u > r || v > c ) continue; q.push ( Node ( u , v , i , tt+1 )); } } } else { int u = tx+dx, v = ty + dy ; if ( u <= 0 || v <= 0 || u > r || v > c ) continue; q.push ( Node ( u , v , td , tt+1)); } } } int main ( ) { while (~scanf ("%d%d%d%d" , &r , &c , &n ,&t )) { memset ( mp , 0 , sizeof ( mp )); memset ( mark , 0 , sizeof ( mark )); for ( int i = 0 ; i < n ; i++ ) { int u,v,z; scanf ("%d%d%d" , &u , &v , &z ); rx[i] = u; ry[i] = v; mp[u][v] += z; } scanf ("%d%d" , &x , &y ); solve (); for ( int i = 0 ; i < n ; i++ ) { int u = rx[i] , v = ry[i]; if ( mark[u][v] ) printf ( "0 %d\n" , mark[u][v] ); else printf ( "1 %d\n" , mp[u][v] ); } } } 相关文章推荐
- 将linux英文系统变成中文系统
- linux下mysql常用的命令
- PropertyPlaceholderConfigurer的使用
- Linux Deepin 2014 cpu温度与频率设定
- linux识别ntfs文件系统
- Linux下 FTP 常见错误 500 530等错误解决方法
- 去掉redhat linux提示注册
- CentOS7启动报sd 0:0:0:0: [sda] Assuming drive cache: write through
- 程序语言入门网站
- hadoop中partition浅析
- log4j.properties配置详解
- 多线程调试必杀技 - GDB的non-stop模式
- Linux下搭建nodejs + npm + express环境
- 创建powershell模块
- OpenDaylight项目:预期标准化战争的结束
- linux之ps命令简单使用
- linux(ubuntu)下分区和格式化sd卡
- linux 硬盘读写性能测试
- 【HDOJ 5336】XYZ and Drops
- 18. Window createPopup() 方法