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;
    }


  • 相关阅读:
    webclassify 用于网页分类的python工具包
    基于Web 开发模式的信息抽取
    携梦远行 » curl 抓取跳转内容
    CharField cannot have a "max_length" greater than 255 when using "unique=True" Google Groups
    并发编程利器Eventlet
    ANSI colored Python logging — Gist
    Fabulous — fabulous v0.1.5 documentation
    让你的博客支持MetaWeblog离线发布_维护记录 站点功能_DangJian's Blog
    Plumber Jack: Colourising logging output in terminals
    ajax客户端与服务端传输字符串
  • 原文地址:https://www.cnblogs.com/mthoutai/p/6767960.html
Copyright © 2011-2022 走看看