FZU--2188--过河(bfs暴力条件判断)
| Time Limit: 3000MS | Memory Limit: 32768KB | 64bit IO Format: %I64d & %I64u |
Description
Input
Output
Sample Input
Sample Output
Hint
第一个样例
次数 船 方向 左岸 右岸(狼 羊)
0: 0 0 3 3 0 0
1: 2 0 > 1 3 2 0
2: 1 0 < 2 3 1 0
3: 2 0 > 0 3 3 0
4: 1 0 < 1 3 2 0
5: 0 2 > 1 1 2 2
6: 1 1 < 2 2 1 1
7: 0 2 > 2 0 1 3
8: 1 0 < 3 0 0 3
9: 2 0 > 1 0 2 3
10: 1 0 < 2 0 1 3
11: 2 0 > 0 0 3 3
Source
#include<stdio.h>
#include<string.h>
#include<queue>
#include<algorithm>
using namespace std;
struct node
{
int a,b,loact,step;
}p,temp;
int m,n,M;
int vis[2][505][505];
void bfs(int x,int y)
{
queue<node>q;
p.a=x;
p.b=y;
p.loact=0;
p.step=0;
memset(vis,0,sizeof(vis));
vis[0][x][y]=1;
q.push(p);
while(!q.empty())
{
p=q.front();
q.pop();
if(p.a==n&&p.b==m&&p.loact==1)
{
printf("%d\n",p.step);
return ;
}
temp.loact=p.loact==1?0:1;
temp.step=p.step+1;
for(int i=0;i<=p.a;i++)
{
for(int j=0;j<=p.b;j++)
{
if(i+j==0)
continue;
if(i<j&&i!=0)
continue;
if(i+j>M)
continue;
if(p.a-i<p.b-j&&p.a-i!=0)
continue;
temp.a=n-p.a+i;
temp.b=m-p.b+j;
if(temp.a<temp.b&&temp.a!=0)
continue;
if(vis[temp.loact][temp.a][temp.b])
continue;
vis[temp.loact][temp.a][temp.b]=1;
q.push(temp);
}
}
}
printf("-1\n");
}
int main()
{
while(scanf("%d%d%d",&n,&m,&M)!=EOF)
{
bfs(n,m);
}
return 0;
}
FZU--2188--过河(bfs暴力条件判断)的更多相关文章
- fzu 2188 过河I
http://acm.fzu.edu.cn/problem.php?pid=2188 过河I Time Limit:3000MS Memory Limit:32768KB 64bit ...
- 农夫过河 (BFS)(队列)
1 .问题描述 要求设计实现农夫过河问题(农夫带着一只狼,一只养,一棵白菜,一次只能带一个东西)如何安全过河. 2 .问题的解决方案: 可以用栈与队列.深度优先搜索算法及广度优先搜索算法相应的原理去解 ...
- C# if中连续几个条件判断
C# if中连续几个条件判断 1.if (条件表达式1 && 条件表达式2) 当条件表达式1为true时 using System; using System.Collections. ...
- js条件判断时隐式类型转换
Javascript 中,数字 0 为假,非0 均为真 在条件判断运算 == 中的转换规则是这样的: 如果比较的两者中有布尔值(Boolean),会把 Boolean 先转换为对应的 Number,即 ...
- 5-3 bash脚本编程之二 条件判断
1. 条件测试的表达式 1. [ expression ] :注意这个中括号的前后都有一个空格 2. [[ expression ]] 3. test expression 2.条件判断的类型 1. ...
- 第10章 Shell编程(3)_字符处理命令和条件判断
3. 字符处理命令 3.1 排序命令:sort (1)sort命令:#sort [选项] 文件名 选项 作用 -f 忽略大小写 -n 以数值型进行排序,默认使用字符串型排序 -r 反向排序 -t 指定 ...
- Nginx if 条件判断
Nginx if 条件判断: 1.公司网站上线有这样的需求: 由于公司网站域名从http到https的转移,在测试阶段需要公司内部进行测试,公司内部局域网访问时强制访问加密的https服务,外部用户访 ...
- shell条件判断与流程控制
一 条件判断式语句 1.按文件类型进行判断 测试类型 作用 -b 文件 判断文件是否存在,并且是否为块设备文件(是块设备文件为真) -c 文件 判断文件是否存在,并且是否为字符设备文件(是字符设备设备 ...
- 为什么说在使用多条件判断时switch case语句比if语句效率高?
在学习JavaScript中的if控制语句和switch控制语句的时候,提到了使用多条件判断时switch case语句比if语句效率高,但是身为小白的我并没有在代码中看出有什么不同.去度娘找了半个小 ...
随机推荐
- [agc015c]nuske vs phantom thnook
题意: 有一个n*m的网格图,每个格子是蓝色或白色.四相邻的两个格子连一条边,保证蓝格子构成一个森林. 有q组询问,每次询问给出一个矩形,问矩形内蓝格子组成的联通块个数. $1\leq n,m\leq ...
- 如何使用外部插件picker
近日有需求做一个职业选择弹框,在网上搜了半天也没合适的: 暴躁大佬协助我DIY一个插件,直接使用,顺滑流畅,随心所欲!特别鸣谢@一样菜 不多BB了,直接撸代码: 引用写在上面: /* 更改职业 */ ...
- LINUX 中 python 版本升级
首先下载源tar包 可利用linux自带下载工具wget下载,如下所示: 1 # wget http://www.python.org/ftp/python/2.7.3/Python-2.7.3.tg ...
- Centos7 安装 opencv
Centos7 安装 opencv CentOS Linux release 7.2.1511 (Core) 1.安装依赖 yum install https://dl.fedorap ...
- Leetcode-Best Time to Buy and Sell Stock -java
题目: Say you have an array for which the ith element is the price of a given stock on day i. If you w ...
- APK反编译去广告大揭秘
APK反编译去广告 具体步骤: 1.下载 apktool 下载地址:https://code.google.com/p/android-apktool/downloads/list 2.通过apkto ...
- [Angular] Short Imports with TypeScript Path Mapping
The idea is change from: import {CoreModule} from '../core/core.module'; to: import {CoreModule} fro ...
- 删除heroku上的数据库记录
部署本地项目到heroku上.在线上插入数据到数据库,本地代码再次更新到heroku,线上的数据记录还存在单是图片丢失.问题还没有解决: 本地代码和heroku代码怎样同步? heroku使用的pg和 ...
- Windows server 2008 布署FTP服务器实例(适用于阿里云)!
Windows server 2008 布署FTP服务器实例(适用于阿里云). 1.打开管理.配置-用户-新建用户,如:ftp_user,并设置password.选择永只是期和password不能更改 ...
- django admin显示多对多字段
参考文档https://jingyan.baidu.com/article/4e5b3e190f55c591901e24b3.html admin.py from .models import *cl ...