码迷,mamicode.com
首页 > 其他好文 > 详细

多校 hdu

时间:2015-07-30 23:26:18      阅读:348      评论:0      收藏:0      [点我收藏+]

标签:acm   hdu   

XYZ and Drops

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


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 (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
 

Source
 

Recommend
wange2014   |   We have carefully selected several similar problems for you:  5338 5337 5336 5335 5334


#include <iostream>
#include <cstdio>
#include <cstring>
#include <queue>
#include <algorithm>
using namespace std;
#define maxn 100 + 5
struct Water
{
    int x, y, d;
}W[maxn*maxn], flag[maxn];
int time, r, c, n;
int d[maxn][maxn];
int go[4][2] = {{0, 1}, {1, 0}, {0, -1}, {-1, 0}};
int tt[maxn][maxn];
int main()
{
    while(~scanf("%d%d%d%d", &r, &c, &n, &time))
    {
        memset(d, 0, sizeof(d));
        memset(tt, -1, sizeof(tt));
        int x, y, num;
        queue<Water> Q;
        for(int i=1; i<=n; i++)
        {
            scanf("%d%d%d", &flag[i].x, &flag[i].y, &num);
            d[flag[i].x][flag[i].y] = num;
        }
        scanf("%d%d", &x, &y);
        for(int i=0; i<4; i++)
        Q.push(Water{x, y, i});
        int tmp, ti = 0;
        while(time--)
        {
            ti++;
            tmp = Q.size();
            if(!tmp)
            break;
            while(tmp--)
            {
                Water w = Q.front();
                Q.pop();
                int xx = w.x + go[w.d][0];
                int yy = w.y + go[w.d][1];
                if(xx > 0 && xx <= r && yy >=0 && yy <= c)
                if(d[xx][yy] == 0)
                {
                    Q.push(Water{xx, yy, w.d});
                }
                else d[xx][yy]++;
            }

            for(int i=1; i<=n; i++)
            {
                 x = flag[i].x, y = flag[i].y;
                 if(tt[x][y] == -1 && d[x][y] > 4)
                 {
                     d[x][y] = 0;
                     tt[x][y] = ti;
                     for(int i=0; i<4; i++)
                     Q.push(Water{x, y, i});
                 }
            }
        }

        for(int i=1; i<=n; i++)
        {
            x = flag[i].x, y = flag[i].y;
            if(tt[x][y] != -1)
                printf("0 %d\n", tt[x][y]);
            else
                printf("1 %d\n", d[x][y]);
        }
    }
    return 0;
}


版权声明:本文为博主原创文章,未经博主允许不得转载。

多校 hdu

标签:acm   hdu   

原文地址:http://blog.csdn.net/dojintian/article/details/47157089

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!