Meteor Shower POJ
来源:互联网 发布:windows脚本编程 编辑:程序博客网 时间:2024/06/16 08:16
D - Meteor Shower
POJ - 3669题意:找到一个不会有流星落下的地方。
思路:先将地图赋初值为-1,输入一个流星的坐标和时间后,就将地图上被流星击中过的地方以及它的四个方向标记为流星落下的时间,如果已经被标记过,并且数值不同,这时应标记为下落时间更小的值。接下来,广搜,找到一个为初值-1的地方即可。
代码:
#include<stdio.h>#include<string.h>#include<queue>using namespace std;int n,Map[310][310],c[5][2]= {0,0,1,0,0,1,-1,0,0,-1};int lu[330][330],d[4][2]= {1,0,0,1,0,-1,-1,0},q;struct yun{ int x,y,s;};int bfs(int x,int y){ yun st,en; queue<yun>Q; st.x=x; st.y=y; st.s=0; lu[x][y]=1; Q.push(st); while(Q.size()) { st=Q.front(); Q.pop(); if(Map[st.x][st.y] == -1)return st.s;//找到没有被流星击中过的地方返回即可。 for(int i=0; i<4; i++)//四个方向。 { int dx=st.x+d[i][0]; int dy=st.y+d[i][1]; if(dx<0||dy<0||lu[dx][dy])continue; if(Map[dx][dy] == -1)return st.s+1;//找到没有被流星击中过的地方返回即可。 if(st.s+1<Map[dx][dy])//当前所走的步数要小于流星落下的时间。 { en.x=dx; en.y=dy; en.s=st.s+1; lu[dx][dy]=1; Q.push(en); } } } return -1;//找不到返回-1.}int main(){ int i,j,x1,y1,z1; scanf("%d",&n); memset(Map,-1,sizeof(Map)); memset(lu,0,sizeof(lu)); for(i=0; i<n; i++) { scanf("%d%d%d",&x1,&y1,&z1); for(j=0; j<5; j++)//五个方向,都定义流星降落的时间。 { int x=c[j][0]+x1; int y=c[j][1]+y1; if(x<0||y<0)continue; if(Map[x][y]!=-1&&Map[x][y]<=z1)continue;//将数值定义成流星落下时更小的时间。 Map[x][y]=z1; } } int p=bfs(0,0); printf("%d\n",p);}
阅读全文
0 0
- POJ 3669 - Meteor Shower
- POJ 3699 Meteor Shower
- poj 3669 Meteor Shower
- poj 3669 Meteor Shower
- POJ-3669-Meteor Shower
- POJ 3669 Meteor Shower
- poj 3669Meteor Shower
- POJ-3669 Meteor Shower
- Poj 3699 Meteor Shower
- poj 3669 Meteor Shower
- POJ 3669 Meteor Shower
- poj 3669 Meteor Shower
- poj 3669 Meteor Shower
- POJ 3669 Meteor Shower
- poj 3669 meteor shower
- poj-3669-Meteor Shower
- POJ 3669:Meteor Shower
- POJ 3669 Meteor Shower
- 先序遍历、中序遍历、后序遍历(二叉树)
- 如何理解deconvolution?
- 能量项链 NOIP2006 Codevs1154
- 程序员面试金典:高度最小的BST、输出单层结点
- OpenVR——驱动接口之IClientTrackedDeviceProvider简介
- Meteor Shower POJ
- 得到三个[10-100)的随机数,按降序排列。注意:只能用if语句
- 【Linux】文件和目录属性及其修改——chgrp、chown、chmod、touch...
- LinkedList简介
- Logo图标的含义
- 解决VS2010警告unsuccessfulbuild”,因为已指定“AlwaysCreate”
- zigbee binding
- CreateEvent的用法
- 复合数据类型