Description






































Input




































Output
























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
#include<iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<vector>
using namespace std;
const int MAXN = 100 + 10;
struct wp
{
int x, y;
int state;
int t;
wp()
{
}
wp( int x, int y, int state, int t )
{
this->x = x;
this->y = y;
this->state = state;
this->t = t;
}
};
struct drop
{
int x, y;
int dir;
int state;
drop()
{ }
drop( int x, int y, int dir,int state )
{
this->x = x;
this->y = y;
this->dir = dir;
this->state = state;
}
};
int dir[4][2] = { {-1,0},{1,0},{0,-1},{0,1} };
wp p[MAXN];
drop d[MAXN * 10];
int Size[MAXN][MAXN];
int n, m, k, t;
bool inline check( int x, int y )
{
return 1 <= x&&x <= n && 1 <= y&&y <= m;
}
int main()
{
while(scanf( "%d%d%d%d", &n, &m, &k, &t ) == 4)
{
int x, y, s;
memset( Size, 0, sizeof Size );
for(int i = 0; i < k; i++)
{
scanf( "%d%d%d", &x, &y, &s );
Size[x][y] = s;
p[i] = wp( x, y, 1, -1 );
}
scanf( "%d%d", &x, &y );
int cnt = 0;
for(int i = 0; i < 4; i++)
{
d[cnt++] = drop( x, y, i, 1 );
}
for(int tt = 1; tt <= t; tt++)
{
for(int i = 0; i < cnt; i++)
{
if(d[i].state == 0) continue;
d[i].x += dir[d[i].dir][0];
d[i].y += dir[d[i].dir][1];
if(!check( d[i].x, d[i].y ))
{
d[i].state = 0;
}
if(Size[d[i].x][d[i].y]>0)
{
Size[d[i].x][d[i].y]++;
d[i].state = 0;
}
}
for(int i = 0; i < k; i++)
{
if(p[i].state == 0)continue;
if(Size[p[i].x][p[i].y]>4)
{
p[i].state = 0;
p[i].t = tt;
Size[p[i].x][p[i].y] = 0;
for(int j = 0; j < 4; j++)
{
d[cnt++] = drop( p[i].x, p[i].y, j, 1 );
}
}
}
}
for(int i = 0; i < k; i++)
{
printf( "%d %d\n", p[i].state, (p[i].state == 0 ? p[i].t : Size[p[i].x][p[i].y]) );
}
}
return 0;
}版权声明:本文为博主原创文章,未经博主允许不得转载。
原文:http://blog.csdn.net/maxichu/article/details/48029219