HDU ACM 1495 非常可乐(广搜BFS)
非常可乐
Time Limit : 2000/1000ms (Java/Other) Memory Limit : 32768/32768K (Java/Other)
Total Submission(s) : 42 Accepted Submission(s) : 21
Font: Times New Roman | Verdana | Georgia
Font Size: ← →
Problem Description
Input
Output
Sample Input
7 4 3
4 1 3
0 0 0
Sample Output
NO
3
Author
Source
#include <iostream>
#include<cstdio>
#include<queue>
#include<cstring>
using namespace std;
struct node
{
int a,b,c,av,bv,cv,step;
};
int ss,n,m,ans;
int f[][][];
int ok(int a,int b,int c)
{
if (a==b && c==) return ;
if (b==c && a==) return ;
if (a==c && b==) return ;
return ;
}
void pour(int* a,int* b,int* av,int* bv,int* step)
{
if (*a>)
{ if (*a>=*bv-*b)
{
*a=*a-(*bv-*b);
*b=*bv;
*step=*step+;
} else
{
*b=*b+*a;
*a=;
*step=*step+;
}
}
return;
}
int bfs()
{
node p;
queue<node> s;
p.a=ss;
p.b=;
p.c=;
p.av=ss;
p.bv=n;
p.cv=m;
p.step=;
s.push(p);
while(!s.empty())
{
node q=s.front();
s.pop();
//a->b
p=q;
pour(&p.a,&p.b,&p.av,&p.bv,&p.step);
if(!f[p.a][p.b][p.c])
{
s.push(p);
f[p.a][p.b][p.c]=;
}
if(ok(p.a,p.b,p.c)) return p.step;
//a->c
p=q;
pour(&p.a,&p.c,&p.av,&p.cv,&p.step);
if(!f[p.a][p.b][p.c])
{
s.push(p);
f[p.a][p.b][p.c]=;
}
if(ok(p.a,p.b,p.c)) return p.step;
//b->c
p=q;
pour(&p.b,&p.c,&p.bv,&p.cv,&p.step);
if(!f[p.a][p.b][p.c])
{
s.push(p);
f[p.a][p.b][p.c]=;
}
if(ok(p.a,p.b,p.c)) return p.step;
//b->a
p=q;
pour(&p.b,&p.a,&p.bv,&p.av,&p.step);
if(!f[p.a][p.b][p.c])
{
s.push(p);
f[p.a][p.b][p.c]=;
}
if(ok(p.a,p.b,p.c)) return p.step;
//c->a
p=q;
pour(&p.c,&p.a,&p.cv,&p.av,&p.step);
if(!f[p.a][p.b][p.c])
{
s.push(p);
f[p.a][p.b][p.c]=;
}
if(ok(p.a,p.b,p.c)) return p.step;
//c->b
p=q;
pour(&p.c,&p.b,&p.cv,&p.bv,&p.step);
if(!f[p.a][p.b][p.c])
{
s.push(p);
f[p.a][p.b][p.c]=;
}
if(ok(p.a,p.b,p.c)) return p.step;
}
return -;
}
int main()
{ while(~scanf("%d%d%d",&ss,&n,&m))
{
if(ss== && n== && m==) break;
if (ss%!=)
{
printf("NO\n");
continue;
}
memset(f,,sizeof(f));
ans=bfs();
if (ans>) printf("%d\n",ans);
else printf("NO\n");
}
return ;
}
HDU ACM 1495 非常可乐(广搜BFS)的更多相关文章
- hdu 1495 非常可乐 广搜
#include<iostream> #include<cstdio> #include<cstring> #include<queue> ][][]; ...
- hdu 1253:胜利大逃亡(基础广搜BFS)
胜利大逃亡 Time Limit: 4000/2000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)Total Submi ...
- hdu 2717 Catch That Cow(广搜bfs)
题目链接:http://i.cnblogs.com/EditPosts.aspx?opt=1 Catch That Cow Time Limit: 5000/2000 MS (Java/Others) ...
- HDU 5652(二分+广搜)
题目链接:http://acm.hust.edu.cn/vjudge/contest/128683#problem/E 题目大意:给定一只含有0和1的地图,0代表可以走的格子,1代表不能走的格 子.之 ...
- Combine String HDU - 5707 dp or 广搜
Combine String HDU - 5707 题目大意:给你三个串a,b,c,问a和b是不是恰好能组成c,也就是a,b是不是c的两个互补的子序列. 根据题意就可以知道对于c的第一个就应该是a第一 ...
- HDU 1253 (简单三维广搜) 胜利大逃亡
奇葩!这么简单的广搜居然爆内存了,而且一直爆,一直爆,Orz 而且我也优化过了的啊,尼玛还是一直爆! 先把代码贴上睡觉去了,明天再来弄 //#define LOCAL #include <ios ...
- hdu 1175 连连看 (广搜,注意解题思维,简单)
题目 解析见代码 #define _CRT_SECURE_NO_WARNINGS //这是非一般的最短路,所以广搜到的最短的路不一定是所要的路线 //所以应该把所有的路径都搜索出来,找到最短的转折数, ...
- poj3126 Prime Path 广搜bfs
题目: The ministers of the cabinet were quite upset by the message from the Chief of Security stating ...
- HDU 1072 Nightmare (广搜)
题目链接 Problem Description Ignatius had a nightmare last night. He found himself in a labyrinth with a ...
随机推荐
- .Net Core Session验证码
1.验证码帮助类 namespace IdeaCore.Services.Common { public class ValidateCodeService : IValidateCodeServic ...
- CevaEclipse - 编译器attribute扩展
1.函数与变量的 Section Attribute void foobar (void) __attribute__ ((section (".CSECT mmm"))); vo ...
- Keyboard Test Utility v1.0.1.0 电脑键盘测试软件绿色版
软件名称: 电脑键盘测试软件绿色版软件语言: 简体中文授权方式: 免费软件运行环境: Win8 / Win7 / Vista / WinXP软件大小: 917KB图片预览: 软件简介:Keyboard ...
- Deep Learning(深度学习)网络资源
Deep Learning(深度学习) ufldl的2个教程(这个没得说,入门绝对的好教程,Ng的,逻辑清晰有练习):一 ufldl的2个教程(这个没得说,入门绝对的好教程,Ng的,逻辑清晰有练习): ...
- 如何使用kaptcha验证码组件
kaptcha是基于SimpleCaptcha的验证码开源项目. kaptcha是纯配置的,使用起来比较友好.如使用了Servlet,所有配置都在web.xml中.如果你在项目中使用了开源框架(比如S ...
- C# 反射相关的东西
public class PlugingManager { //插件装载器 public ArrayList Plugins = new ArrayList(); ...
- OA系统出现窗口拦截的解决办法
我们使用oa时候,有时候会出现“你打开了窗口拦截功能”.如图 出现窗口被拦截主要有三种情况,分别是IE浏览器本身拦截功能.第三方插件(如百度工具栏.搜搜工具栏.谷歌工具栏等).第三方浏览器拦截功能(如 ...
- laravel 获取最后一条sql的小函数
function lastSql(){ $sql = DB::getQueryLog(); $query = end($sql); return $query; }
- recursion 递归以及递归的缺点
递归定义的算法有两部分: 递归基:直接定义最简单情况下的函数值: 递归步:通过较为简单情况下的函数值定义一般情况下的函数值. 应用条件与准则: (1)问题具有某种可借用的类同自身的子问题描述的性质: ...
- openwrt 中make的使用
make 命令简单说明 make V=99 V=99表示输出详细的debug信息 make world 表示编译所有 make j=2 V=99 如是多核CPU,加j=2 选项理论上能加快编译速度 m ...