HDOJ 5336 XYZ and Drops 模拟


暴力模拟


XYZ and Drops

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


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

1r100 1c100 1n100 1T10000
 

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 . ( 1sizei4 )
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
 

Source
2015 Multi-University Training Contest 4
 



/* ***********************************************
Author        :CKboss
Created Time  :2015年07月30日 星期四 14时52分47秒
File Name     :1010.cpp
************************************************ */

#include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <string>
#include <cmath>
#include <cstdlib>
#include <vector>
#include <queue>
#include <set>
#include <map>

using namespace std;

const int dir_x[4]={0,0,-1,1};
const int dir_y[4]={1,-1,0,0};

int r,c,n,T;

int mid[111][111];
int SZ[111],Time[111];

int X[111],Y[111];

void init()
{
    memset(SZ,0,sizeof(SZ));
    memset(mid,0,sizeof(mid));
    memset(Time,0,sizeof(Time));
}

struct Node
{
    int x,y,d,t;

    void toString()
    {
        printf("(%d,%d) d: %d t: %d\n",x,y,d,t);
    }
};

bool isInside(int x,int y)
{
    if((x>=1&&x<=r)&&(y>=1&&y<=c)) return true;
    return false;
}

void solve(int _x,int _y)
{
    queue<Node> q;

    for(int i=0;i<4;i++)
    {
        Node nd;
        nd.x=_x; nd.y=_y; nd.d=i; nd.t=0;
        q.push(nd);
    }

    while(!q.empty())
    {
        Node u=q.front(); q.pop();

        //u.toString();

        /// boom waterdrop number
        int bbb=-1;

        int d=u.d;
        Node v;

        v.x=u.x+dir_x[d];
        v.y=u.y+dir_y[d];
        v.d=u.d;
        v.t=u.t+1;



        /// is in side
        if(isInside(v.x,v.y)==false) continue;

        int id=mid[v.x][v.y];

        /// zhe waterdrop is boomming 
        if(id==0)
        {
            if(v.t<T)
            {
                q.push(v);
            }
        }
        else
        {
            if(Time[id]!=0)
            {
                if(Time[id]>=v.t) continue;
                else
                {
                    if(v.t<T)
                    {
                        q.push(v);
                    }
                }
            }
            /// meet with waterdrop
            else if(Time[id]==0)
            {
                SZ[id]++;
                if(SZ[id]>4)
                {
                    Time[id]=v.t;
                    //mid[v.x][v.y]=0;
                    bbb=id;
                }
            }
        }

        if(bbb!=-1)
        {
            /// add 4 new node
            for(int j=0;j<4;j++)
            {
                Node n1;
                n1.x=X[bbb]; n1.y=Y[bbb];
                n1.d=j; n1.t=v.t;

                if(n1.t<T) 
                {
                    q.push(n1);
                }
            }
        }
    }

    //cout<<".......end............\n";
}

int main()
{
    //freopen("in.txt","r",stdin);
    //freopen("out.txt","w",stdout);

    while(scanf("%d%d%d%d",&r,&c,&n,&T)!=EOF)
    {
        init();
        for(int i=1,s;i<=n;i++)
        {
            scanf("%d%d%d",X+i,Y+i,&s);
            int x=X[i],y=Y[i];
            mid[x][y]=i;
            SZ[i]=s;
        }

        int x,y;
        scanf("%d%d",&x,&y);
        solve(x,y);

        for(int i=1;i<=n;i++)
        {
            if(Time[i]!=0) printf("%d %d\n",0,Time[i]);
            else printf("%d %d\n",1,SZ[i]);
        }
    }
    
    return 0;
}


你可能感兴趣的:(HDOJ 5336 XYZ and Drops 模拟)