[BZOJ] 1611: [Usaco2008 Feb]Meteor Shower流星雨
2017-09-02 19:01
387 查看
1611: [Usaco2008 Feb]Meteor Shower流星雨
Time Limit: 5 Sec Memory Limit: 64 MBSubmit: 1654 Solved: 707
[Submit][Status][Discuss]
Description
去年偶们湖南遭受N年不遇到冰冻灾害,现在芙蓉哥哥则听说另一个骇人听闻的消息: 一场流星雨即将袭击整个霸中,由于流星体积过大,它们无法在撞击到地面前燃烧殆尽, 届时将会对它撞到的一切东西造成毁灭性的打击。很自然地,芙蓉哥哥开始担心自己的 安全问题。以霸中至In型男名誉起誓,他一定要在被流星砸到前,到达一个安全的地方 (也就是说,一块不会被任何流星砸到的土地)。如果将霸中放入一个直角坐标系中, 芙蓉哥哥现在的位置是原点,并且,芙蓉哥哥不能踏上一块被流星砸过的土地。根据预 报,一共有M颗流星(1 <= M <= 50,000)会坠落在霸中上,其中第i颗流星会在时刻 T_i (0 <= T_i <= 1,000)砸在坐标为(X_i, Y_i) (0 <= X_i <= 300;0 <= Y_i <= 300) 的格子里。流星的力量会将它所在的格子,以及周围4个相邻的格子都化为焦土,当然 芙蓉哥哥也无法再在这些格子上行走。芙蓉哥哥在时刻0开始行动,它只能在第一象限中, 平行于坐标轴行动,每1个时刻中,她能移动到相邻的(一般是4个)格子中的任意一个, 当然目标格子要没有被烧焦才行。如果一个格子在时刻t被流星撞击或烧焦,那么芙蓉哥哥 只能在t之前的时刻在这个格子里出现。请你计算一下,芙蓉哥哥最少需要多少时间才能到 达一个安全的格子。
Input
* 第1行: 1个正整数:M * 第2..M+1行: 第i+1行为3个用空格隔开的整数:X_i,Y_i,以及T_i
Output
输出1个整数,即芙蓉哥哥逃生所花的最少时间。如果芙蓉哥哥无论如何都无法在流星雨中存活下来,输出-1
Sample Input
40 0 2
2 1 2
1 1 2
0 3 5
输入说明:
一共有4颗流星将坠落在霸中,它们落地点的坐标分别是(0, 0),(2, 1),(1, 1)
以及(0, 3),时刻分别为2,2,2,5。
Sample Output
5HINT
样例图示
#include<cstdio> #include<iostream> #include<queue> using namespace std; const int dir[4][2] = {{0,1},{1,0},{-1,0},{0,-1}},inf = 0x3f3f3f3f; int map[400][400],n; struct node{ int x,y,time; }; bool Judge(int x,int y){ return x < 0 || y < 0; } void Init(){ for(int i = 0;i <= 355;i++){ for(int j = 0;j <= 355;j++){ map[i][j] = inf; } } } void Print(){ for(int i = 0;i <= 7;i++){ for(int j = 0;j <= 7;j++){ if(map[i][j] != inf) printf("%d ",map[i][j]); else cout << 0 << ' '; }cout << endl; } cout << endl; } void bfs(){ queue<node> Q; Q.push((node){0,0,0}); // book[0][0] = true; while(!Q.empty()){ node now = Q.front(); Q.pop(); for(int i = 0;i < 4;i++){ int nowx = now.x+dir[i][0]; int nowy = now.y+dir[i][1]; if(Judge(nowx,nowy) || map[nowx][nowy] <= now.time+1) continue; if(map[nowx][nowy] == inf){ printf("%d",now.time+1); return; } map[nowx][nowy] = now.time+1; Q.push((node){nowx,nowy,now.time+1}); // Print(); } } printf("-1"); } int main(){ scanf("%d",&n); Init(); for(int i = 1;i <= n;i++){ int a,b,t; scanf("%d%d%d",&a,&b,&t); map[a][b] = min(map[a][b],t); for(int i = 0;i < 4;i++){ int nowx = a+dir[i][0]; int nowy = b+dir[i][1]; if(Judge(nowx,nowy)) continue; map[nowx][nowy] = min(map[nowx][nowy],t); } } if(map[0][0] == inf) printf("0"); else if(map[0][0] == 0) printf("-1"); else bfs(); return 0; }亏我还拿我XT哥的代码对拍了好久qwq果然智商太低
相关文章推荐
- bzoj1611【Usaco2008 Feb】Meteor Shower 流星雨
- bzoj1611[Usaco2008 Feb]Meteor Shower流星雨
- BZOJ——1611: [Usaco2008 Feb]Meteor Shower流星雨
- 【BZOJ】1611: [Usaco2008 Feb]Meteor Shower流星雨(bfs)
- bzoj:1611 [Usaco2008 Feb]Meteor Shower流星雨
- BZOJ 1611: [Usaco2008 Feb]Meteor Shower流星雨
- bzoj 1611: [Usaco2008 Feb]Meteor Shower流星雨
- BZOJ 1611: [Usaco2008 Feb]Meteor 4000 Shower流星雨
- 模拟+BFS-BZOJ-1611-[Usaco2008 Feb]Meteor Shower流星雨
- 【bzoj1611】【Usaco2008 Feb】Meteor Shower流星雨 (bfs)题解&代码
- BZOJ1611: [Usaco2008 Feb]Meteor Shower流星雨
- BZOJ_1611_[Usaco2008_Feb]_Meteor_Shower流星雨_(bfs)
- 【bzoj 1611】 [Usaco2008 Feb]Meteor Shower流星雨 bfs
- 【BZOJ 1611】 [Usaco2008 Feb]Meteor Shower流星雨
- Bzoj 1611: [Usaco2008 Feb]Meteor Shower流星雨
- bzoj 1611: [Usaco2008 Feb]Meteor Shower流星雨(DP)
- bzoj 1611: [Usaco2008 Feb]Meteor Shower流星雨【BFS】
- 【bzoj1593】【poj3667】[Usaco2008 Feb]Hotel 旅馆
- bzoj 1610: [Usaco2008 Feb]Line连线游戏
- bzoj 1610: [Usaco2008 Feb]Line连线游戏【瞎搞】