BZOJ 1611 Usaco Meteor Shower

好多奶牛题目是真的坑啊,不标数据范围或者题目描述残缺。。。
让我WA了3次才过。

回归正题,一道不算难的BFS题目。
注意棋盘范围是301 如果走出301也算成功逃生(无语=W=)

#include <cstdio>
#include <algorithm>
#include <queue>
#include <cstring>
 
struct Point{
    int x,y,Time;
};
 
std::queue<Point>Q;
 
const int INF=0x3f3f3f3f;
int n,End=-1;
int x,y,t;
int vis[305][305];
int Die[305][305];
 
int fx[5]={0,0,-1,0,1},fy[5]={0,-1,0,1,0};
 
void BFS(){
    while( !Q.empty() ){
        Point Start = Q.front();
        Q.pop();
        for(int i=1;i<=4;i++){
            int tx = Start.x+fx[i];
            int ty = Start.y+fy[i];
            if(tx>=301 && ty>=301){
                End = Start.Time+1;
                return;
            }
            if(tx>=0 && ty>=0 && tx<=301 && ty<=301 && !vis[tx][ty] ){
                if(Start.Time+1>=Die[tx][ty]) continue;
                if(Die[tx][ty]==INF){
                    End = Start.Time+1;
                    return;
                }
                vis[tx][ty]=1;
                Point now;
                now.x=tx;
                now.y=ty;
                now.Time=Start.Time+1;
                Q.push(now);
            }
        }
    }
    return;
}
 
int main(){
    memset(Die,INF,sizeof(Die));
    scanf("%d",&n);
    for(int i=1;i<=n;i++){
        scanf("%d%d%d",&x,&y,&t);
        Die[x][y]=std::min(Die[x][y],t);
        for(int i=1;i<=4;i++){
            int nx = x+fx[i];
            int ny = y+fy[i];
            if(ny >= 0 && nx>=0 && nx<=301 && ny<=301) Die[nx][ny]=std::min(Die[nx][ny],t);
        }
    }
    Point New;
    New.x=0;
    New.y=0;
    New.Time=0;
    vis[0][0]=1;
    Q.push(New);
    if(Die[0][0]==INF){
        printf("0\n");
        return 0;
    }
    BFS();
    printf("%d\n",End);
    return 0;
}
时间: 2024-10-12 16:31:39

BZOJ 1611 Usaco Meteor Shower的相关文章

【bzoj 1611】 [Usaco2008 Feb]Meteor Shower流星雨 bfs

题目:http://www.lydsy.com/JudgeOnline/problem.php?id=1611 1611: [Usaco2008 Feb]Meteor Shower流星雨 Time Limit: 5 Sec Memory Limit: 64 MB Submit: 1272 Solved: 557 [Submit][Status][Discuss] Description 去年偶们湖南遭受N年不遇到冰冻灾害,现在芙蓉哥哥则听说另一个骇人听闻的消息: 一场流星雨即将袭击整个霸中,由于

1611: [Usaco2008 Feb]Meteor Shower流星雨

1611: [Usaco2008 Feb]Meteor Shower流星雨 Time Limit: 5 Sec  Memory Limit: 64 MBSubmit: 1010  Solved: 446[Submit][Status][Discuss] Description 去年偶们湖南遭受N年不遇到冰冻灾害,现在芙蓉哥哥则听说另一个骇人听闻的消息: 一场流星雨即将袭击整个霸中,由于流星体积过大,它们无法在撞击到地面前燃烧殆尽, 届时将会对它撞到的一切东西造成毁灭性的打击.很自然地,芙蓉哥哥开

[题解]poj Meteor Shower

Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 16313   Accepted: 4291 Description Bessie hears that an extraordinary meteor shower is coming; reports say that these meteors will crash into earth and destroy anything they hit. Anxious fo

poj 3669 Meteor Shower(bfs)

Description Bessie hears that an extraordinary meteor shower is coming; reports say that these meteors will crash into earth and destroy anything they hit. Anxious for her safety, she vows to find her way to a safe location (one that is never destroy

POJ3669(Meteor Shower)(bfs求最短路)

Meteor Shower Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 12642   Accepted: 3414 Description Bessie hears that an extraordinary meteor shower is coming; reports say that these meteors will crash into earth and destroy anything they h

POJ 3669 Meteor Shower (BFS + 预处理)

Meteor Shower Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 9677   Accepted: 2718 Description Bessie hears that an extraordinary meteor shower is coming; reports say that these meteors will crash into earth and destroy anything they hi

POJ3669 Meteor Shower 【BFS】

Meteor Shower Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 9163   Accepted: 2594 Description Bessie hears that an extraordinary meteor shower is coming; reports say that these meteors will crash into earth and destroy anything they hi

Meteor Shower (poj 3669 bfs)

Language: Default Meteor Shower Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 9929   Accepted: 2771 Description Bessie hears that an extraordinary meteor shower is coming; reports say that these meteors will crash into earth and destro

【POJ 3669】Meteor Shower

Meteor Shower Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 11661   Accepted: 3182 Description Bessie hears that an extraordinary meteor shower is coming; reports say that these meteors will crash into earth and destroy anything they h