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语句效率高,但是身为小白的我并没有在代码中看出有什么不同.去度娘找了半个小 ...
随机推荐
- WebRTC | Failed to execute 'setLocalDescription' on 'RTCPeerConnection': Failed to parse SessionDescription. a=msid: Missing track ID in msid attribute.
1.问题回放 使用如下代码获取局域网IP报错 (代码来源:https://github.com/diafygi/webrtc-ips 日期:2019-02-16) Uncaught (in promi ...
- Vir-manager 创建虚拟机
- centos7 bond0 双网卡配置
[root@openldap ~]# ifconfig bond0: flags=5187<UP,BROADCAST,RUNNING,MASTER,MULTICAST> mtu 1500 ...
- Linux快速入门打开你的学习之道
Linux快速入门打开你的学习之道 相信看到这篇文章的你一定是想要学习Linux,或者已经在学习Linux的人了,那我们就可以一起探讨一下,学习Linux如何快速入门呢? 首先,希望大家弄清楚自己为什 ...
- python 面向对象 类方法,静态方法,property
property 内置装饰器函数 只在面向对象使用 把方法当初属性使用(方法不加参数) 例子: class Rectangle: def __init__(self,long,wide,color): ...
- 2019年北航OO第三单元(JML规格任务)总结
一.JML简介 1.1 JML与契约式设计 说起JML,就不得不提到契约式设计(Design by Contract).这种设计模式的始祖是1986年的Eiffel语言.它是一种限定了软件中每个元素所 ...
- OpenJudge 1031 Lausanne Capitale Olympique
Lausanne Capitale Olympique Time Limit: 1000ms Memory Limit: 65536KB This problem will be judged on ...
- ios面试题1
iOS面试题 1.写一个NSString类的实现 + (id)initWithCString:(c*****t char *)nullTerminatedCString encoding:(NSS ...
- excle查找操作-vlookup的使用心得
百度了一下vlookup的语法规则: 该函数的语法规则例如以下: VLOOKUP(lookup_value,table_array,col_index_num,range_lookup) 參数 简单说 ...
- zzulioj--1775-- 和尚特烦恼1——是不是素数(素数水题)
1775: 和尚特烦恼1--是不是素数 Time Limit: 2 Sec Memory Limit: 128 MB Submit: 563 Solved: 193 SubmitStatusWeb ...