poj 3278 找牛
来源:互联网 发布:考研大数据 编辑:程序博客网 时间:2024/06/03 22:38
此题暴露出 广搜 还是很差.....首先是想不到用搜索 , 然后是 不知道写标记 ,要明白广搜的用法,光知道走迷宫问题要标记,这个就不标记了,哎......明早再写一遍
# include<stdio.h># include<cstdlib># include<string.h># include<queue># include<algorithm>using namespace std;int n,m;queue<int> q;int step[100010];int vis[100010];int rear,front;int BFS(){ int i; q.push(n); step[n]=0; vis[n]=1; while(!q.empty()){ front=q.front(); q.pop(); for(i=0 ;i<3; i++){ if(i==0) rear=front+1; if(i==1) rear=front-1; if(i==2) rear=front*2; if(rear>=0 && rear<=100000 && vis[rear]==0){ vis[rear]=1; step[rear]=step[front]+1; q.push(rear); } if(rear== m) return step[rear]; } }return -1;}int main(){ while(scanf("%d %d",&n,&m)!=EOF){ memset(step,0,sizeof(step)); memset(vis,0,sizeof(vis)); printf("%d\n" ,BFS()); }}
0 0
- poj 3278 找牛
- poj 2800 找规律
- POJ 1068(找规律)
- 博弈 找规律 poj 2484
- POJ 2456 (二分找值)
- POJ 1019 数学找规律
- POJ 2010 二分找中位数
- POJ - 3579(二分法找中位数)
- POJ-2368-Buttons [找规律]
- poj 1063 找规律题目
- 找牛
- POJ 1218 囚犯问题 数学题找规律
- poj 1501 dfs(找字符串)
- POJ 3268 01背包+找最小
- POJ 1095 找规律+递归打印
- POJ 2484 A Funny Game(找规律)
- Poj 2800 Joseph's Problem - 找规律
- POJ 2183 Bovine Math Geniuses 找循环
- LoadRunner设置登录检查点
- 论在LCT上下放标记
- Python模块包中__init__.py文件 精髓
- 九度OJ 1111:单词替换 (查找)
- HashTable-HashMap(Android,Java最常见面试题)
- poj 3278 找牛
- Animation Clips(动画剪辑)
- 堆中的路径
- android学习路线:如何成长为高级工程师
- 【codevs1282】约瑟夫问题,卡数据ing?
- org.springframework.beans.factory.BeanDefinitionStoreException: IOException parsing XML document fro
- LoadRunner自带实例安装问题could not open ftp port21-port is already used by another server
- 浅谈MDK环境下使用#include <stdio.h>的问题
- Py4JJavaError: An error occurred while calling o18.sql. : java.lang.RuntimeException: