• hdu5336XYZ and Drops


    题意:给出r*c的网格,有的网格为空。有的有水。再给出一个爆炸点,从这个点向四周爆出四个水滴,若碰到水则融为一体,若碰到其它水滴直接跑过去互不影响。每秒可跑一格,若水中水滴数量超过4则爆开。问T秒后网格的状态是如何的。


    做法:因为数据有点多,直接用set优化bfs一次走一步的过程。变成一次走多步就可以。



    #include<map>
    #include<string>
    #include<cstring>
    #include<cstdio>
    #include<cstdlib>
    #include<cmath>
    #include<queue>
    #include<vector>
    #include<iostream>
    #include<algorithm>
    #include<bitset>
    #include<climits>
    #include<list>
    #include<iomanip>
    #include<stack>
    #include<set>
    using namespace std;
    int num[110][110];
    set<int>sr[110],sc[110];
    int r,c,T;
    bool beyond(int tr,int tc)
    {
        return tr<1||tc<1||tr>r||tc>c;
    }
    struct point
    {
        int tr,tc,flag;
        point(){}
        point(int tr,int tc,int flag)
        {
            this->tr=tr;
            this->tc=tc;
            this->flag=flag;
        }
    }hehe[110];
    vector<point>bx;
    bool vis[110][110];
    void gao(int tr,int tc,int flag,int cnt)
    {
        if(!beyond(tr,tc)&&!vis[tr][tc])
        {
            if(num[tr][tc]>0)
            {
                num[tr][tc]++;
                if(num[tr][tc]>4)
                {
                    sr[tr].erase(tc);
                    sc[tc].erase(tr);
                    num[tr][tc]=-cnt;
                    bx.push_back(point(tr,tc,0));
                    vis[tr][tc]=1;
                }
            }
            else
                bx.push_back(point(tr,tc,flag));
        }
    }
    void work()
    {
        set<int>::iterator it;
        int cnt=0,p=0;
        while(1)
        {
            int len=bx.size(),mn=INT_MAX;
            if(p==len)
                return;
            for(int i=p;i<len;i++)
            {
                point t=bx[i];
                int tr=t.tr,tc=t.tc,flag=t.flag;
                if(flag==0||flag==1)
                {
                    it=sc[tc].lower_bound(tr);
                    if(it!=sc[tc].begin())
                    {
                        it--;
                        mn=min(mn,tr-*it);
                    }
                }
                if(flag==0||flag==2)
                {
                    it=sc[tc].upper_bound(tr);
                    if(it!=sc[tc].end())
                        mn=min(mn,*it-tr);
                }
                if(flag==0||flag==3)
                {
                    it=sr[tr].lower_bound(tc);
                    if(it!=sr[tr].begin())
                    {
                        it--;
                        mn=min(mn,tc-*it);
                    }
                }
                if(flag==0||flag==4)
                {
                    it=sr[tr].upper_bound(tc);
                    if(it!=sr[tr].end())
                        mn=min(mn,*it-tc);
                }
            }
            if(cnt+mn>T)
                return;
            cnt+=mn;
            memset(vis,0,sizeof(vis));
            for(int i=p;i<len;i++)
            {
                point t=bx[i];
                int tr=t.tr,tc=t.tc,flag=t.flag;
                if(flag==0||flag==1)
                {
                    tr-=mn;
                    gao(tr,tc,1,cnt);
                    tr+=mn;
                }
                if(flag==0||flag==2)
                {
                    tr+=mn;
                    gao(tr,tc,2,cnt);
                    tr-=mn;
                }
                if(flag==0||flag==3)
                {
                    tc-=mn;
                    gao(tr,tc,3,cnt);
                    tc+=mn;
                }
                if(flag==0||flag==4)
                {
                    tc+=mn;
                    gao(tr,tc,4,cnt);
                    tc-=mn;
                }
            }
            p=len;
        }
    }
    int main()
    {
        int n;
        while(scanf("%d%d%d%d",&r,&c,&n,&T)!=EOF)
        {
            for(int i=1;i<=r;i++)
                sr[i].clear();
            for(int i=1;i<=c;i++)
                sc[i].clear();
            memset(num,0,sizeof(num));
            for(int i=0;i<n;i++)
            {
                int t;
                scanf("%d%d%d",&hehe[i].tr,&hehe[i].tc,&t);
                sr[hehe[i].tr].insert(hehe[i].tc);
                sc[hehe[i].tc].insert(hehe[i].tr);
                num[hehe[i].tr][hehe[i].tc]=t;
            }
            int tr,tc;
            scanf("%d%d",&tr,&tc);
            bx.clear();
            bx.push_back(point(tr,tc,0));
            work();
            for(int i=0;i<n;i++)
            {
                tr=hehe[i].tr;
                tc=hehe[i].tc;
                int t=num[tr][tc];
                if(t<0)
                    printf("0 %d
    ",-t);
                else
                    printf("1 %d
    ",t);
            }
        }
    }


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


    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 (xy), before the first second there is a waterdrop cracking at position (xy). XYZ wants to know each waterdrop's status after T seconds, 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


  • 相关阅读:
    软件工程课后作业3:如何返回一个整数数组中最大子数组的和
    软件工程课后作业2:四则运算题目扩展:可指定题目数量并且支持真分数运算
    软件工程课后作业1:三十道四则运算题目
    团队作业3返回整数数组中最大子数组的和(多个数组)
    求一个二维数组所有子数组和的最大值(郭少周,陈泽)
    郭少周和陈泽两人合作课堂练习和课下作业
    学生成绩查询系统个人NABCD
    返回一个整数组的最大子数组和
    个人项目3
    返回一个二维整数组中最大子数组的和
  • 原文地址:https://www.cnblogs.com/mfmdaoyou/p/6921044.html
Copyright © 2020-2023  润新知