//n个水团,当水团的大小大于4时
//就会炸开,变为4个小水滴向四个方向移动
//每个小水滴一秒移动一格
//当小水滴遇到大水团,大水团大小加1,小水滴消失
//0秒时有一个水团在sx,sy炸开
//问t秒时各个水团的状态
//用队列保存每个水滴的位置,方向,模拟就行
#include<iostream>
#include<cstdio>
#include<cstring>
#include<queue>
using namespace std ;
const int maxn = 110 ;
int map[maxn][maxn] ;
int id[maxn][maxn] ;
int dx[4] = {0 , 0 , 1 , -1} ;
int dy[4] = {1 , -1 , 0 , 0} ;
struct node
{
int x , y ;
int d ;
} ;
int r , c , t , n ;
int a[maxn] , b[maxn] ;
void bfs(int sx , int sy)
{
queue<node> que[2] ;
queue<int> q ;
for(int i = 0 ;i < 4;i++)
que[1].push(node{sx,sy,i}) ;
for(int i = 1;i <= t;i++)
{
while(que[i%2].size())
{
node now = que[i%2].front() ;
que[i%2].pop() ;
int nx = now.x + dx[now.d] ;
int ny = now.y + dy[now.d] ;
if(nx < 1 || nx > r || ny < 1 || ny > c)
continue ;
if(map[nx][ny]){
map[nx][ny]++ ;
q.push(nx) ;
q.push(ny) ;
}
else
que[(i+1)%2].push(node{nx,ny,now.d}) ;
}
while(q.size())
{
int nx = q.front();q.pop() ;
int ny = q.front();q.pop() ;
if(map[nx][ny] > 4)
{
a[id[nx][ny]] = 0 ;
b[id[nx][ny]] = i ;
map[nx][ny] = 0 ;
for(int j = 0;j < 4;j++)
que[(i+1)%2].push(node{nx,ny,j}) ;
}
}
}
}
int main()
{
//freopen("d:\\in.txt" , "r" , stdin) ;
while(~scanf("%d%d%d%d" , &r , &c , &n , &t))
{
memset(map , 0 , sizeof(map)) ;
for(int i = 1;i <= n;i++)
{
int x , y , v ;
scanf("%d%d%d" , &x , &y, &v) ;
map[x][y] = v ;
id[x][y] = i ;
}
int sx , sy ;
scanf("%d %d" , &sx , &sy) ;
if(sx >= 1 && sx <= r && sy >= 1 && sy <= n)
bfs(sx , sy) ;
for(int i = 1;i <= r;i++)
for(int j = 1;j <= c;j++)
if(map[i][j]){
a[id[i][j]] = 1 ;
b[id[i][j]] = map[i][j] ;
}
for(int i = 1;i <= n;i++)
printf("%d %d\n" , a[i] , b[i]) ;
}
return 0 ;
}
hdu5336XYZ and Drops bfs模拟
最新推荐文章于 2018-07-24 19:59:03 发布