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 ...
随机推荐
- webapi中的扩展点
Extension Points Web API provides extension points for some parts of the routing process. Interface ...
- HttpReceiveRequestEntityBody 使用应注意的地方
如果EntityBody数据很大,调用此函数是不能完全接收全部数据的,我们不能简单的判断 1: BYTE* pBuffer = new BYTE[4096]; 2: ZeroMemory(pBuffe ...
- 【Machine Learning in Action --4】朴素贝叶斯电子邮件垃圾过滤
摘要:这里用的是词袋模型,即一个词在文档中出现不止一次,每个单词可以出现多次. 1.准备数据:切分文本 前一节过滤网站恶意留言中词向量是给定的,下面介绍如何从文本文档中构建自己的词列表 先举例说明,在 ...
- 值得一提:关于 HDFS 的 file size 和 block size
转 http://blog.csdn.net/samhacker/article/details/23089157?utm_source=tuicool&utm_medium=referral ...
- Java操作*.properties
java中的properties文件是一种配置文件,主要用于表达配置信息,文件类型为*.properties,格式为文本文件,文件的内容是格式是"键=值"的格式,在properti ...
- VoIP的话音质量测量方法
严重的呼叫质量和性能管理问题会影响VoIP (Voice over IP)系统的运作.网络管理员等人需要理解基本的呼叫质量测量技术才能很好地监测.管理和诊断在VoIP中出现的这些问题.本文介绍了常用的 ...
- WKWebView与Js交互
首先打开webstorm,将最下面h5拷贝到html中.然后导入工程 #define kMessageHandlerName @"mymobile" 1.创建配置类 - (WKWe ...
- array_walk与array_map 的不同 array_filter
array_walk 主要是要对数组内的每个值进行操作,操作结果影响原来的数组 array_map主要是对数组中的值进行操作后返回数组,以得到一个新数组 wallk 可以没有返回值 map要有,因 ...
- leetcode83,删除有序链表中的重复元素
Given a sorted linked list, delete all duplicates such that each element appear only once. For examp ...
- swf version 与flash player 对应关系
2013-04-16更新:更新Flash Player 11.7/AIR 3.7正式版. 详细链接FlashPlayer 11.7详情 2013-03-10更新:更新Flash Player 11.6 ...