HDU 4527 小明系列故事——玩转十滴水 2013腾讯编程马拉松初赛第五场第二题

题目地址: http://acm.hdu.edu.cn/showproblem.php?pid=4527

 

这个和我们玩的3366游戏十滴水差不多,规则就是当水滴大于4的时候会爆裂像4个方向各传递一滴水。

有一点要注意的是,水滴的速度是相同的,所以可能有大于等于2滴水滴同时到达某一地方。

 

 

代码如下:

#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <cstring>
#include <string>
#include <algorithm>
#include <vector>
#include <set>
#include <map>
#include <queue>
using namespace std;

/*
freopen("input.txt",  "r", stdin);  //读数据
freopen("output.txt", "w", stdout); //注释掉此句则输出到控制台
*/

int xh[7][7],t[4][2]={1,0,-1,0,0,1,0,-1};//方向
int visit[7][7];//记录时间

struct xiaohao
{
    int x,y,t,d;//x,y坐标,t代表时间,d代表方向
}w,e;

void dfs(int x,int y)
{
    int i;
    queue<xiaohao> q;
    xh[x][y]++;
    if(xh[x][y]>4)
    {
        visit[x][y]=0;
        w.x=x;w.y=y;w.t=0;w.d=-1;
        q.push(w);
    }
    while(!q.empty())
    {
        w=q.front();
        q.pop();
        if(w.d==-1)//w.d等与-1表示爆裂,其他表示分裂方向
            xh[w.x][w.y]=0;
        for(i=0;i<4;i++)
        {
            if(w.d!=-1&&w.d!=i)//如果不是爆裂也不是沿着原方向,则continue
                continue;
            int xx=w.x+t[i][0],yy=w.y+t[i][1];
            if(xx>0&&xx<=6&&yy>0&&yy<=6)
            {
                if(xh[xx][yy]==0)
                {
                    e.x=xx;e.y=yy;e.t=w.t+1;e.d=i;
                    q.push(e);
                }
                else if(xh[xx][yy]<4)//小于4,直接++
                {
                    xh[xx][yy]++;
                }
                else if(xh[xx][yy]==4)//这个地方只能写等于4,因为有同时到达可能大于四
                {
                    xh[xx][yy]++;
                    visit[xx][yy]=w.t+1;
                    e.x=xx;e.y=yy;e.t=w.t+1;e.d=-1;
                    q.push(e);
                }
                else
                {
                    //如果快于或等于上一次到达,则++
                    if(w.t+1<=visit[xx][yy])
                        xh[xx][yy]++;
                    //比上一次慢那么继续前进
                    else
                    {
                        e.x=xx;e.y=yy;e.t=w.t+1;e.d=i;
                        q.push(e);
                    }
                }
            }
        }
    }
}

int main()
{
    int i,j,x,y,m;
    while(cin>>xh[1][1])
    {
        for(i=1;i<=6;i++)
            for(j=1;j<=6;j++)
                if(i!=1||j!=1)
                    scanf("%d",&xh[i][j]);
        cin>>m;
        while(m--)
        {
            memset(visit,-1,sizeof(visit));
            scanf("%d%d",&x,&y);
            dfs(x,y);
        }
        for(i=1;i<=6;i++)
            printf("%d %d %d %d %d %d\n",xh[i][1],xh[i][2],xh[i][3],xh[i][4],xh[i][5],xh[i][6]);
        printf("\n");
    }
    return 520;
}


 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值