非常可乐

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

大家一定觉的运动以后喝可乐是一件很惬意的事情,但是seeyou却不这么认为。因为每次当seeyou买了可乐以后,阿牛就要求和seeyou一起分享这一瓶可乐,而且一定要喝的和seeyou一样多。但seeyou的手中只有两个杯子,它们的容量分别是N 毫升和M 毫升 可乐的体积为S (S<101)毫升 (正好装满一瓶) ,它们三个之间可以相互倒可乐 (都是没有刻度的,且 S==N+M,101>S>0,N>0,M>0) 。聪明的ACMER你们说他们能平分吗?如果能请输出倒可乐的最少的次数,如果不能输出"NO"。

Input

三个整数 : S 可乐的体积 , N 和 M是两个杯子的容量,以"0 0 0"结束。

Output

如果能平分的话请输出最少要倒的次数,否则输出"NO"。

Sample Input

7 4 3
4 1 3
0 0 0

Sample Output

NO
3

Author

seeyou

Source

“2006校园文化活动月”之“校庆杯”大学生程序设计竞赛暨杭州电子科技大学第四届大学生程序设计竞赛

#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)的更多相关文章

  1. hdu 1495 非常可乐 广搜

    #include<iostream> #include<cstdio> #include<cstring> #include<queue> ][][]; ...

  2. hdu 1253:胜利大逃亡(基础广搜BFS)

    胜利大逃亡 Time Limit: 4000/2000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)Total Submi ...

  3. hdu 2717 Catch That Cow(广搜bfs)

    题目链接:http://i.cnblogs.com/EditPosts.aspx?opt=1 Catch That Cow Time Limit: 5000/2000 MS (Java/Others) ...

  4. HDU 5652(二分+广搜)

    题目链接:http://acm.hust.edu.cn/vjudge/contest/128683#problem/E 题目大意:给定一只含有0和1的地图,0代表可以走的格子,1代表不能走的格 子.之 ...

  5. Combine String HDU - 5707 dp or 广搜

    Combine String HDU - 5707 题目大意:给你三个串a,b,c,问a和b是不是恰好能组成c,也就是a,b是不是c的两个互补的子序列. 根据题意就可以知道对于c的第一个就应该是a第一 ...

  6. HDU 1253 (简单三维广搜) 胜利大逃亡

    奇葩!这么简单的广搜居然爆内存了,而且一直爆,一直爆,Orz 而且我也优化过了的啊,尼玛还是一直爆! 先把代码贴上睡觉去了,明天再来弄 //#define LOCAL #include <ios ...

  7. hdu 1175 连连看 (广搜,注意解题思维,简单)

    题目 解析见代码 #define _CRT_SECURE_NO_WARNINGS //这是非一般的最短路,所以广搜到的最短的路不一定是所要的路线 //所以应该把所有的路径都搜索出来,找到最短的转折数, ...

  8. poj3126 Prime Path 广搜bfs

    题目: The ministers of the cabinet were quite upset by the message from the Chief of Security stating ...

  9. HDU 1072 Nightmare (广搜)

    题目链接 Problem Description Ignatius had a nightmare last night. He found himself in a labyrinth with a ...

随机推荐

  1. LeetCode OJ 122. Best Time to Buy and Sell Stock II

    Say you have an array for which the ith element is the price of a given stock on day i. Design an al ...

  2. Rational Rose 2003 逆向工程转换C++ / VC++ 6.0源代码成UML类图

    目录 1.安装&破解Rational Rose 2003 1.1 安装Rose 2003 1.2 破解Rose 2003 1.3运行出错“没有找到suite objects.dl” 2. Ra ...

  3. 多线程---静态同步函数的锁是class(转载)

    /** 如果同步函数被静态修饰,那么他的锁就是该方法所在类的字节码文件对象 类名.class 静态进内存时,内存中没有本类对象,但是一定有该类对应的字节码文件对象. 该对象就是:类名.class   ...

  4. wpf 异步加载 只需6段代码

    private BackgroundWorker worker = null; ProgressBar probar = new ProgressBar(); private int percentV ...

  5. CentOS修复“OpenSSL Heartbleed漏洞”方法

    转载 http://www.coolhots.net/article/229.shtml

  6. Ecstore1.2启用mongodb添加索引

    配置config(连接mongo) mongo define('KVSTORE_STORAGE', 'base_kvstore_mongodb'); define('MONGODB_SERVER_CO ...

  7. Core Animation中的基础动画

    基础动画 在开发过程中很多情况下通过基础动画就可以满足开发需求,前面例子中使用的UIView代码块进行图像放大缩小的演示动画也是基础动画(在iOS7 中UIView也对关键帧动画进行了封装),只是UI ...

  8. perl Socket接收超时设置

    一般来说, IO::Socket::INET里的Timeout设置是对于conncet的 如果你想设置recv接收超时, 可以这样设置: usr Socket: ...... , )); #注意这里p ...

  9. [PHP] 安装和配置

    Apachehttpd-2.2.19-win64mysql5.6Phphttp://www.php.net/downloads.php 5.4Phpeclipsehttp://www.phpeclip ...

  10. ssl证书验证

    当我们在访问https网站时,浏览器就会自动下载该网站的SSL证书,并对证书的安全性进行检查. 其他概念不说了,有效期之类的验证也不说了.只说数字证书的真实性和可信性验证. 1.CA下发给网站的证书是 ...