HDU 5336 XYZ and Drops(bfs)

本文介绍了一个名为Drops的游戏模拟算法。游戏在一个r*c的网格上进行,每个网格单元可能为空或者包含一滴水,每滴水有一个大小属性。当水滴的大小超过4时,它会分裂成四个小水滴向四个方向移动。每秒每个小水滴向指定方向移动一个单位距离,并可能与其他小水滴或原有水滴融合增加其大小。文章提供了游戏模拟的具体实现代码。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

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 rc 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 (xy), before the first second there is a waterdrop cracking at position (xy). XYZ wants to know each waterdrop's status after Tseconds, can you help him?

1r1001c1001n1001T10000
 

Input
The first line contains four integers rcn and Tn stands for the numbers of waterdrops at the beginning. 
Each line of the following n lines contains three integers xiyisizei, meaning that the i-th waterdrop is at position (xiyi) and its size is sizei. (1sizei4)
The next line contains two integers xy

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 AiBi
If the i-th waterdrop cracks in T seconds, Ai=0Bi= the time when it cracked. 
If the i-th waterdrop doesn't crack in T seconds, Ai=1Bi= 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;
}


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值