Meteor Shower(3669)
来源:互联网 发布:阿国网络随笔 编辑:程序博客网 时间:2024/06/08 05:53
大致题意:有一些东西会在指定的时间袭击某个点。,这个点的周围四个点也会被波及,现在有个人在(0,0)位置, 想要走到安全位置,只在第一象限, 问要走多少步, 如果不可以就输出-1.
方法:先处理出点会在什么时候不安全,然后用bfs求最短的步数。
注意:有可能会在0的时候就不安全。
#include <cstdio>#include <cstring>#include <iostream>#include <algorithm>#include <queue>using namespace std;int n, cont[400][400];int d[4][2] = {{1,0}, {-1,0}, {0,1}, {0,-1}};bool vis[400][400];struct node{ int a, b, c;}pp[50100];bool cmp(node mm, node tt){ return mm.c < tt.c;}struct pos{ int x, y, time; pos(){} pos(int xx, int yy, int tt): x(xx), y(yy), time(tt){}};queue<pos>que;int main(){ int i, j; while(scanf("%d", &n) != EOF){ memset(cont, -1, sizeof(cont)); memset(vis, 0, sizeof(vis)); while(!que.empty()){ que.pop(); } for(i = 1; i <= n; i++){ scanf("%d%d%d", &pp[i].a, &pp[i].b, &pp[i].c); } sort(pp+1, pp+1+n, cmp); for(i = 1; i <= n; i++){ node nd = pp[i]; if(cont[nd.a][nd.b] == -1) cont[nd.a][nd.b] = nd.c; for(j = 0; j < 4; j++){ int xx = nd.a + d[j][0]; int yy = nd.b + d[j][1]; if(xx<0 || yy < 0) continue; if(cont[xx][yy] == -1) cont[xx][yy] = nd.c; } } que.push(pos(0,0,0)); vis[0][0] = 1; int flag = 0; pos temp; while(!que.empty()){ temp = que.front(); if(cont[temp.x][temp.y] == -1){ flag = 1; break; } que.pop(); for(i = 0; i < 4; i++){ int xx = temp.x + d[i][0]; int yy = temp.y + d[i][1]; if(xx<0 || yy<0) continue; if(vis[xx][yy] == 1) continue; if(temp.time+1 >= cont[xx][yy] && cont[xx][yy]!=-1) continue; que.push(pos(xx, yy, temp.time+1)); vis[xx][yy] = 1; } } if(flag == 1) printf("%d\n", temp.time); else printf("-1\n"); } return 0;}
0 0
- Meteor Shower(3669)
- Meteor Shower(POJ-3669)
- PKU 3669 Meteor Shower(BFS)
- POJ 3669 - Meteor Shower(广搜)
- POJ 3669 Meteor Shower (BFS)
- POJ 3669 Meteor Shower (BFS + 预处理)
- POJ 3669 Meteor Shower (bfs)
- POJ 3669 Meteor Shower(bfs)
- poj 3669 Meteor Shower(BFS)
- POJ 3669 Meteor Shower(BFS)
- POJ 3669-Meteor Shower(BFS)
- POJ - 3669 - Meteor Shower(bfs)
- POJ 3669 Meteor Shower(BFS)
- POJ 3669 Meteor Shower(BFS)
- POJ 3669 Meteor Shower(BFS)
- POJ 3669 Meteor Shower(bfs)
- poj 3669-Meteor Shower(简单bfs)
- POJ 3669 Meteor Shower(BFS)
- Netfilter分析
- java快捷方式小程序
- Cisco WebEx设备ssl证书安装指南
- WARNING: REMOTE HOST IDENTIFICATION HAS CHANGED解决方法
- php把用户输入的内容写入文件中的代码
- Meteor Shower(3669)
- SpringMVC下ajax提交form表单与后台接收
- Ubuntu下JNI的简单使用
- Lost connection to MySQL server at ‘reading initial communication packet
- Android Service知识(上)
- [JSON-lib框架]使java对象、json、xml之间的转换不再困难
- 打印出图形(菱形)
- android 音频系统工作流程梳理
- 数据库解析——10条关于数据库的技巧和经验