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 ...
随机推荐
- sql优化原则
尽量使用性能高的比如left join等,尽量减少数据查询的column,尽量不要查询冗余数据,like的话“%%”是没有 办法使用索引的,但是“%”是可以使用索引的 having以前一直不知道到底真 ...
- 洛谷-语文成绩-[有奖]洛谷5月月赛:kkksc03的三大神器
题目背景 Background语文考试结束了,成绩还是一如既往地有问题. 题目描述 Description语文老师总是写错成绩,所以当她修改成绩的时候,总是累得不行.她总是要一遍遍地给某些同学增加分数 ...
- word异常关闭,找到丢失的word
Word模板路径位置 XP系统用户默认模板路径一般在 C:\Documents and Settings\Administrator\Application Data\Microsoft\Templa ...
- G - Zombie’s Treasure Chest(动态规划专项)
G - Zombie’s Treasure Chest Time Limit:1000MS Memory Limit:32768KB 64bit IO Format:%I64d &am ...
- CSS的基本概念
<!--CSS 一.概念:CSS的全称是Cascading Style Sheets,层叠样式表,用来控制HTML标签样式,在美化网页中起到非常重要的作用 CSS的编写格式是键值对形式的,比如 ...
- HTML-input标签需设置的属性
<input placeholder="这里输入门店名称" autocomplete="off" id="" name="& ...
- Pyramid of Glasses(递推)
Pyramid of Glasses time limit per test 1 second memory limit per test 256 megabytes input standard i ...
- javascript 事件响应
1.基本事件 2.点击事件 <html> <head> <script type="text/javascript"> function add ...
- Vim 配置Markdown
通过vundle工具安装以下插件: vim-markdown 语法高亮 vim-markdown-preview.vim 通过浏览器实时预览(支持同步滚动) -/.vimrc vundle部分添 ...
- APP测试中的头疼脑热:测试人员如何驱动开发做好自测
如今,随着移动互联网的浪潮越翻越涌,移动APP测试工作的现状已经成了那本"家家难念"的经.不管公司大小,不管测试哪种类型的APP,让广泛测试者苦不堪言的就属重复性最多,测试工作量最 ...