zoukankan      html  css  js  c++  java
  • HDU 5336 XYZ and Drops

    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

    来个优先级队列记录一下时间,暴力的搞吧

    #include<cstdio>
    #include<cstring>
    #include<cmath>
    #include<vector>
    #include<queue>
    #include<stack>
    #include<map>
    #include<algorithm>
    #include<string>
    #pragma comment(linker, "/STACK:102400000,102400000")
    typedef long long ll;
    using namespace std;
    const ll maxn=105;
    int T,n,m,t,f[maxn][maxn],x,y,a[maxn],b[maxn],c[maxn][maxn];
    
    struct point
    {
        int x,y,z,t,now;
        point(){}
        point(int x,int y,int z,int t,int now):
        x(x),y(y),z(z),t(t),now(now) {};
        bool operator <(const point &a) const
        {
            return now+t>a.now+a.t;
        }
    };
    
    int get(int x,int y,int d)
    {
        if (d&1)
        {
            if (d==1)
            {
                for (int i=y+1;i<=m;i++)
                    if (f[x][i]) return i-y;
                return 0;
            }
            else 
            {
                for (int i=y-1;i>=1;i--)
                    if (f[x][i]) return y-i;
                return 0;
            }
        }
        else 
        {
            if (d==0) 
            {
                for (int i=x-1;i>=1;i--)
                    if (f[i][y]) return x-i;
                return 0;
            }
            else 
            {
                for (int i=x+1;i<=n;i++)
                    if (f[i][y]) return i-x;
                return 0;
            }
        }
    }
    
    int main()
    {
        //scanf("%d",&T);
        while (~scanf("%d%d%d%d",&n,&m,&t,&T))
        {
            memset(f,0,sizeof(f));
            memset(c,0,sizeof(c));
            for (int i=1;i<=t;i++)
            {
                scanf("%d%d",&x,&y);
                a[i]=x;    b[i]=y;
                scanf("%d",&f[x][y]);
            }
            scanf("%d%d",&x,&y);
            priority_queue<point> p;
            for (int i=0;i<4;i++) 
            {
                int k=get(x,y,i);
                if (k>0) p.push(point(x,y,i,k,0));
            }
            while (!p.empty())
            {
                point tp,q=p.top();    p.pop();
                
                for (;;p.pop())
                {
                    if (p.empty()) break;
                    tp=p.top();
                    if(tp.now+tp.t!=q.now+q.t) break;
                    int k=get(tp.x,tp.y,tp.z);
                    if (!k) continue;
                    if (k!=tp.t) p.push(point(tp.x,tp.y,tp.z,k,tp.now));
                    else 
                   {
                    if (k+tp.now>T) break;
                    if (tp.z==0) x=tp.x-k,y=tp.y;
                    if (tp.z==1) x=tp.x,y=tp.y+k;
                    if (tp.z==2) x=tp.x+k,y=tp.y;
                    if (tp.z==3) x=tp.x,y=tp.y-k;
                    f[x][y]++;
                    }
                }
                int k=get(q.x,q.y,q.z);
                if (k) 
                if (k!=q.t) p.push(point(q.x,q.y,q.z,k,q.now));
                else 
                {
                    if (k+q.now>T) break;
                    if (q.z==0) x=q.x-k,y=q.y;
                    if (q.z==1) x=q.x,y=q.y+k;
                    if (q.z==2) x=q.x+k,y=q.y;
                    if (q.z==3) x=q.x,y=q.y-k;
                    f[x][y]++;
                }
                for(int i=1;i<=t;i++)
                {
                    x=a[i];    y=b[i];
                    if (f[x][y]>4)
                    {
                        f[x][y]=0;
                        c[x][y]=q.t+q.now;
                        for (int j=0;j<4;j++) 
                        {
                            int u=get(x,y,j);
                            if (u>0) p.push(point(x,y,j,u,q.t+q.now));
                        }
                    }
                }
            }
            for (int i=1;i<=t;i++)
            {
                if (f[a[i]][b[i]]) printf("1 %d
    ",f[a[i]][b[i]]);
                else printf("0 %d
    ",c[a[i]][b[i]]);
            }
        }
        return 0;
    }


  • 相关阅读:
    Java数据结构和算法(2)之稀疏数组
    Java数据结构和算法(1)之队列
    Redis之Redis的数据类型
    Redis之Redis入门介绍
    Redis之NoSql入门和概述(二)
    rpc(二、springboot2.3.2+dubbo2.7.7)
    rpc(一、基础)
    zookeeper(二、curatorAPI使用)
    zookeeper(一、集群部署)
    项目部署(三、docker+Jenkins+springboot部署)
  • 原文地址:https://www.cnblogs.com/mthoutai/p/6767960.html
Copyright © 2011-2022 走看看