zoukankan      html  css  js  c++  java
  • 《3432: Meteor Shower》

    一开始以为只能在第一象限。。

    这题主要就是可能0~300的点全都不是安全的,所以bfs的判断边界要到305才行。

    然后,可能开始的点会被旁边的点炸到,这样开始就死了。

    #include<bits/stdc++.h>
    using namespace std;
    typedef long long LL;
    typedef pair<int,int> pii;
    const int N = 2e4+5;
    const int M = 1e6+5;
    const LL Mod = 1e9 + 7;
    #define pi acos(-1)
    #define INF 1e18
    #define CT0 cin.tie(0),cout.tie(0)
    #define IO ios::sync_with_stdio(false)
    #define dbg(ax) cout << "now this num is " << ax << endl;
    namespace FASTIO{
        inline LL read(){
            LL x = 0,f = 1;char c = getchar();
            while(c < '0' || c > '9'){if(c == '-')f = -1;c = getchar();}
            while(c >= '0' && c <= '9'){x = (x << 1) + (x << 3) + (c ^ 48);c = getchar();}
            return x * f;
        }
    }
    using namespace FASTIO;
    
    int a[305][305],MI[305][305],b[4][2] = {1,0,-1,0,0,1,0,-1};
    bool vis[305][305];
    struct Node{int x,y,tim;};
    int bfs(int x,int y)
    {
        queue<Node> Q;
        Q.push(Node{x,y,0});
        vis[x][y] = 1;
        while(!Q.empty())
        {
            Node q = Q.front();
            Q.pop();
            if(a[q.x][q.y] != -1) return q.tim;
            for(int i = 0;i < 4;++i)
            {
                int px = q.x + b[i][0];
                int py = q.y + b[i][1];
                if(px >= 0 && px < 305 && py >= 0 && py < 305 && !vis[px][py] && q.tim + 1 < MI[px][py])
                {
                    vis[px][py] = 1;
                    Q.push(Node{px,py,q.tim + 1});
                }
            }
        }
        return -1;
    }
    int main()
    {
        int m;
        while(~scanf("%d",&m))
        {
            memset(a,0,sizeof(a));
            memset(vis,0,sizeof(vis));
            memset(MI,0x3f,sizeof(MI));
            for(int i = 1;i <= m;++i)
            {
                int x,y,t;x = read(),y = read(),t = read();
                a[x][y] = -1;
                MI[x][y] = min(MI[x][y],t);
                for(int j = 0;j < 4;++j)
                {
                    int px = x + b[j][0];
                    int py = y + b[j][1];
                    if(px >= 0 && py >= 0)
                    {
                        a[px][py] = -1;
                        MI[px][py] = min(MI[px][py],t);
                    }
                }
            }
            if(MI[0][0] <= 0) printf("-1
    ");
            else printf("%d
    ",bfs(0,0));
        }
        //system("pause");
        return 0;
    }
    View Code
  • 相关阅读:
    Codeforces Global Round 11
    2018-2019 ICPC, Asia Najing
    Codeforces Round #675 (Div. 2) ABCDE
    AtCoder Regular Contest 104 D(卡常)
    Navigator History Location
    键盘移动div
    键盘事件
    事件的传播
    事件的绑定
    事件的委派
  • 原文地址:https://www.cnblogs.com/zwjzwj/p/14076175.html
Copyright © 2011-2022 走看看