HDU 5336 XYZ and Drops(bfs)
2015-07-31 13:06
351 查看
XYZ and Drops
Time Limit: 3000/1500 MS (Java/Others) Memory Limit: 65536/65536 K (Java/Others)Total Submission(s): 736 Accepted Submission(s): 203
Problem Description
XYZ is playing an interesting game called "drops". It is played on a r∗c grid.
Each grid cell is either empty, or occupied by a waterdrop. Each waterdrop has a property "size". The waterdrop cracks when its size is larger than 4, and produces 4 small drops moving towards 4 different directions (up, down, left and right).
In every second, every small drop moves to the next cell of its direction. It is possible that multiple small drops can be at same cell, and they won't collide. Then for each cell occupied by a waterdrop, the waterdrop's size increases by the number of the
small drops in this cell, and these small drops disappears.
You are given a game and a position (x, y),
before the first second there is a waterdrop cracking at position (x, y).
XYZ wants to know each waterdrop's status after Tseconds,
can you help him?
1≤r≤100, 1≤c≤100, 1≤n≤100, 1≤T≤10000
Input
The first line contains four integers r, c, n and T. n stands
for the numbers of waterdrops at the beginning.
Each line of the following n lines
contains three integers xi, yi, sizei,
meaning that the i-th
waterdrop is at position (xi, yi)
and its size is sizei.
(1≤sizei≤4)
The next line contains two integers x, y.
It is guaranteed that all the positions in the input are distinct.
Multiple test cases (about 100 cases), please read until EOF (End Of File).
Output
n lines.
Each line contains two integers Ai, Bi:
If the i-th
waterdrop cracks in T seconds, Ai=0, Bi= the
time when it cracked.
If the i-th
waterdrop doesn't crack in T seconds, Ai=1, Bi= its
size after T seconds.
Sample Input
4 4 5 10
2 1 4
2 3 3
2 4 4
3 1 2
4 3 4
4 4
Sample Output
0 5
0 3
0 2
1 3
0 1
Author
XJZX
直接代码:
#include<cstdio>
#include<cstring>
#include<vector>
#include<iostream>
#include <algorithm>
#include <queue>
using namespace std;
int Size[110][110];
bool vis[110][110];
int r, c, n ,T;
int dir[4][2] = {{0, -1}, {0, 1}, {-1, 0}, {1, 0}};
int dx[10010], dy[10010];
int time[110][110];
int crash[110][110];
struct P
{
int x, y, dis, t;
}now;
queue <P> ac;
bool ok(int x, int y)
{
if(x >= 1 && x <= r && y >= 1 && y <= c)
return true;
else
return false;
}
int main()
{
while(~scanf("%d%d%d%d", &r, &c, &n, &T))
{
memset(Size, 0, sizeof(Size));
memset(vis, 0, sizeof(vis));
memset(crash, -1, sizeof(crash));
for(int i=0; i<n; i++)
{
scanf("%d%d", &dx[i], &dy[i]);
scanf("%d", &Size[dx[i]][dy[i]]);
vis[dx[i]][dy[i]] = true;
}
int sx, sy;
scanf("%d%d", &sx, &sy);
Size[sx][sy] = 5;
vis[sx][sy] = true;
ac.push((P){sx, sy, 0, 0});
while(!ac.empty())
{
now = ac.front();
ac.pop();
int x = now.x, y = now.y, dis = now.dis, t = now.t;
if(crash[x][y] == t) continue;
if(vis[x][y])
{
Size[x][y]++;
if(Size[x][y] > 4)
{
crash[x][y] = t;
vis[x][y] = false;
time[x][y] = t;
t = t + 1;
for(int i = 0; i < 4; i++)
{
int xx = x + dir[i][0], yy = y + dir[i][1];
if(ok(xx, yy) && t <= T)
{
ac.push((P){xx, yy, i, t});
}
}
}
}
else
{
x = x + dir[dis][0], y = y + dir[dis][1], t = t + 1;
if(ok(x, y) && t <= T)
ac.push((P){x, y, dis, t});
}
}
for(int i=0; i<n; i++)
{
if(vis[dx[i]][dy[i]])
{
printf("1 %d\n", Size[dx[i]][dy[i]]);
}
else
{
printf("0 %d\n", time[dx[i]][dy[i]]);
}
}
}
return 0;
}
相关文章推荐
- shell脚本中的if
- CentOS 5 centos 6下安装Axel插件加速yum下载
- centos 配置Openssl并创建证书
- CentOS系统Nginx安装
- Docker网络功能
- windows系统中安装配置tomcat
- 使用Gitblog和Markdown搭建自己的博客网站
- 用jdbc连接mysql数据库(tomcat服务器内置连接池篇)
- Deployment failure on Tomcat 6.x. Could not copy all resources to C:\tomcat6\webapps\OAPMS.
- hadoop入门--子项目
- Linux常用命令大全
- 安装ecshop 常见的 Strict Standards: array_shift()和Deprecated: preg_replace():
- 手动编译安装LAMP架构,并且实现nagios图形化监控(七)
- django结合nginx部署
- 网站压力测试工具Webbench介绍
- OpenCV 3 CUDA小测试
- Linux rpm 命令参数使用详解[介绍和应用]
- 网站后台登录页面始终始终为父窗体的解决办法
- 【资源分享】迅为 iTOP-4412开发板平台详解
- django结合apache部署