模拟-HDOJ-5336-XYZ and Drops

本文介绍了一款名为“drops”的游戏模拟程序,该程序在一个r*c的网格上进行,涉及水滴的移动、分裂及相互作用。初始状态下,网格中包含若干水滴,每个水滴具有一定的大小。当水滴大小超过阈值时会分裂成四个小水滴,并向四周扩散。

XYZ and Drops

Time Limit: 3000/1500 MS (Java/Others) Memory Limit: 65536/65536 K (Java/Others)
Total Submission(s): 1550 Accepted Submission(s): 516

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 T seconds, 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

模拟大小水滴。

//
//  main.cpp
//  150730-1010
//
//  Created by 袁子涵 on 15/7/30.
//  Copyright (c) 2015年 袁子涵. All rights reserved.
//

#include <iostream>
#include <stdio.h>
#include <string.h>

using namespace std;

int x,y;
int r,c,n,T;
int map[110][110];
int book[110][110];


typedef struct wt
{
    int x,y,direction;
}WT;

typedef struct water
{
    WT ball[4];
    int x,y,size;
    int A,B;
}Water;

Water wtr[110];



int main(int argc, const char * argv[]) {
    int times;
    while (scanf("%d%d%d%d",&r,&c,&n,&T)!=EOF) {
        memset(map, 0, sizeof(map));
        memset(book, 0, sizeof(book));
        for (int i=1; i<=n; i++) {
            cin >> wtr[i].x >> wtr[i].y >> wtr[i].size;
            wtr[i].A=1;
            wtr[i].B=wtr[i].size;
            map[wtr[i].x][wtr[i].y]=wtr[i].size;
            book[wtr[i].x][wtr[i].y]=1;
        }
        cin >> x >>y;
        times=T;
        wtr[0].A=0;
        map[x][y]+=4;
        wtr[0].x=x;
        wtr[0].y=y;
        for (int i=0; i<4; i++) {
            wtr[0].ball[i].x=x;
            wtr[0].ball[i].y=y;
            wtr[0].ball[i].direction=i+1;
        }
        while (times--) {

//            
//            for (int i=1; i<=r; i++) {
//                for (int j=1; j<=c; j++) {
//                    cout << map[i][j];
//                }
//                cout << endl;
//            }
//            cout <<endl<<endl;





            //先看各个小水珠
            for (int i=0; i<=n; i++) {
                //当已经爆裂后
                if (wtr[i].A==0) {
                    //四个小水珠
                    for (int j=0; j<4; j++) {
                        //如果小水珠还在
                        if (wtr[i].ball[j].direction!=-1) {
                            //相应的移动
                            switch (wtr[i].ball[j].direction) {
                                case 1:
                                    if (wtr[i].ball[j].x==1) {
                                        map[wtr[i].ball[j].x][wtr[i].ball[j].y]--;
                                        wtr[i].ball[j].direction=-1;
                                        break;
                                    }
                                    map[wtr[i].ball[j].x][wtr[i].ball[j].y]--;
                                    wtr[i].ball[j].x--;
                                    map[wtr[i].ball[j].x][wtr[i].ball[j].y]++;
                                    if (book[wtr[i].ball[j].x][wtr[i].ball[j].y]) {
                                        wtr[i].ball[j].direction=-1;
                                    }
                                    break;
                                case 2:
                                    if (wtr[i].ball[j].x==r) {
                                        map[wtr[i].ball[j].x][wtr[i].ball[j].y]--;
                                        wtr[i].ball[j].direction=-1;
                                        break;
                                    }
                                    map[wtr[i].ball[j].x][wtr[i].ball[j].y]--;
                                    wtr[i].ball[j].x++;
                                    map[wtr[i].ball[j].x][wtr[i].ball[j].y]++;
                                    if (book[wtr[i].ball[j].x][wtr[i].ball[j].y]) {
                                        wtr[i].ball[j].direction=-1;
                                    }
                                    break;
                                case 3:
                                    if (wtr[i].ball[j].y==1) {
                                        map[wtr[i].ball[j].x][wtr[i].ball[j].y]--;
                                        wtr[i].ball[j].direction=-1;
                                        break;
                                    }
                                    map[wtr[i].ball[j].x][wtr[i].ball[j].y]--;
                                    wtr[i].ball[j].y--;
                                    map[wtr[i].ball[j].x][wtr[i].ball[j].y]++;
                                    if (book[wtr[i].ball[j].x][wtr[i].ball[j].y]) {
                                        wtr[i].ball[j].direction=-1;
                                    }
                                    break;
                                case 4:
                                    if (wtr[i].ball[j].y==c) {
                                        map[wtr[i].ball[j].x][wtr[i].ball[j].y]--;
                                        wtr[i].ball[j].direction=-1;
                                        break;
                                    }
                                    map[wtr[i].ball[j].x][wtr[i].ball[j].y]--;
                                    wtr[i].ball[j].y++;
                                    map[wtr[i].ball[j].x][wtr[i].ball[j].y]++;
                                    if (book[wtr[i].ball[j].x][wtr[i].ball[j].y]) {
                                        wtr[i].ball[j].direction=-1;
                                    }
                                    break;
                                default:
                                    break;
                            }
                        }
                    }
                    continue;
                }
                //水滴未爆裂时
                continue;
            }
            //判断是否有新的水珠爆裂
            for (int i=1; i<=n; i++) {
                //如果还没有爆裂
                if (wtr[i].A==1) {
                    if (map[wtr[i].x][wtr[i].y]>4) {
                        wtr[i].A=0;
                        wtr[i].B=T-times;
                        book[wtr[i].x][wtr[i].y]=0;
                        map[wtr[i].x][wtr[i].y]=4;
                        //clear1(wtr[i].x, wtr[i].y);
                        //自身爆出小水珠
                        for (int j=0; j<4; j++) {
                            wtr[i].ball[j].x=wtr[i].x;
                            wtr[i].ball[j].y=wtr[i].y;
                            wtr[i].ball[j].direction=j+1;
                        }
                    }
                    //如果小于4
                    else if (map[wtr[i].x][wtr[i].y]<=4)
                    {
                        wtr[i].B=map[wtr[i].x][wtr[i].y];
                        wtr[i].size=map[wtr[i].x][wtr[i].y];
                        //clear1(wtr[i].x, wtr[i].y);
                    }
                }
            }
        }
        //读出数据,输出
        for (int i=1; i<=n; i++) {
            cout << wtr[i].A << " " << wtr[i].B << endl;
        }
    }
    return 0;
}
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值