HDU 5336(2015多校4)-XYZ and Drops(bfs)
2015-08-01 16:21
471 查看
题目地址:HDU 5336
题意:有一个r 行 c 列的格子,给出n个格子里有水滴的大小。再给出时间限制T,使得水滴从(sx,sy)位置开始爆破,当飞渐的水遇到格子里的静态水时就会聚在一起,当聚集的水滴大小>4时就会爆破。问在T时给定的n个位置格子里的水滴情况,如果没有爆破就输出:1 格子里水滴大小。否则输出:0 爆破的时间。
题意:有一个r 行 c 列的格子,给出n个格子里有水滴的大小。再给出时间限制T,使得水滴从(sx,sy)位置开始爆破,当飞渐的水遇到格子里的静态水时就会聚在一起,当聚集的水滴大小>4时就会爆破。问在T时给定的n个位置格子里的水滴情况,如果没有爆破就输出:1 格子里水滴大小。否则输出:0 爆破的时间。
#include <stdio.h> #include <math.h> #include <string.h> #include <stdlib.h> #include <iostream> #include <sstream> #include <algorithm> #include <set> #include <queue> #include <stack> #include <map> #pragma comment(linker, "/STACK:102400000,102400000") using namespace std; typedef long long LL; const int inf=0x3f3f3f3f; const double pi= acos(-1.0); const double esp=1e-6; int mp[110][110]; int time[110][110]; int jx[]= {0,1,0,-1}; int jy[]= {1,0,-1,0}; int r,c,n,T; int sx,sy; struct drop { int x,y; int time; int papa; } f1,f2; void bfs(int xx,int yy) { queue<drop>q; f1.x=xx; f1.y=yy ; f1.time=0; f1.papa=-1; q.push(f1); while(!q.empty()){ f1=q.front(); q.pop(); if(f1.papa>=0){ f2.x=f1.x+jx[f1.papa]; f2.y=f1.y+jy[f1.papa]; f2.time=f1.time+1; if(f2.x>=1&&f2.x<=r&&f2.y>=1&&f2.y<=c&&f2.time<=T){ if(mp[f2.x][f2.y]){ mp[f2.x][f2.y]++; if(mp[f2.x][f2.y]==5){ f2.papa=-1; q.push(f2); } } else{ f2.papa=f1.papa; q.push(f2); } } } else{ time[f1.x][f1.y]=f1.time; mp[f1.x][f1.y]=0; for(int i=0; i<4; i++){ f2.x=f1.x+jx[i]; f2.y=f1.y+jy[i]; f2.time=f1.time+1; if(f2.x>=1&&f2.x<=r&&f2.y>=1&&f2.y<=c&&f2.time<=T){ if(mp[f2.x][f2.y]){ mp[f2.x][f2.y]++; if(mp[f2.x][f2.y]==5){ f2.papa=-1; q.push(f2); } } else{ f2.papa=i; q.push(f2); } } } } } } int main() { int v; drop node[110]; while(~scanf("%d %d %d %d",&r,&c,&n,&T)) { memset(mp,0,sizeof(mp)); for(int i=0;i<n;i++) { scanf("%d %d %d",&sx,&sy,&v); node[i].x=sx; node[i].y=sy; mp[sx][sy]+=v; } scanf("%d %d",&sx,&sy); bfs(sx,sy); for(int i=0;i<n;i++) if(mp[node[i].x][node[i].y]) printf("1 %d\n",mp[node[i].x][node[i].y]); else printf("0 %d\n",time[node[i].x][node[i].y]); } } /* 同一时间到达同一个水滴(所以代码里是==5而不是>4) 4 4 5 100 1 1 4 1 2 3 1 3 4 1 4 4 2 3 4 2 4 1 4 1 4 0 2 0 1 0 1 */
相关文章推荐
- 在CentOS上搭建LAMP+vsftpd环境的简单指南
- 在Apache服务器上添加虚拟主机功能的方法
- linux下 echo 输出字体颜色的用法
- Linux下tomcat配置优化
- squid 访问控制说明
- squid 安装简单说明
- squid 编译参数说明
- 在win8(win8.1)电脑上安装IIS,配置web服务器,发布网站
- Target runtime Apache Tomcat v7.0 is not defined.错误解决方法
- MFC中添加OpenGL
- [odroid-pc] ubuntu12.04 安装jdk-6u45-linux-x64.bin
- centos6.5下postgres-XC集群安装与配置
- 网站移植,从window的WAMP 转移到线上linux的LNMP
- Linux下实现简单Echo中继服务器
- CentOS中MySQL的开机自动启动开启与关闭
- 高效Linux之Terminal下实用快捷键
- 树莓派+罗技270摄像头+mjpg_streamer实现网路监控
- Tomcat6 一些调优设置内存和连接数
- POJ3258——二分——River Hopscotch
- ZH奶酪:Ubuntu 14.04安装LAMP(Linux,Apache,MySQL,PHP)