Description

  大家一定觉的运动以后喝可乐是一件很惬意的事情,但是seeyou却不这么认为。因为每次当seeyou买了可乐以后,阿牛就要求和seeyou一起分享 这一瓶可乐,而且一定要喝的和seeyou一样多。但seeyou的手中只有两个杯子,它们的容量分别是N 毫升和M 毫升 可乐的体积为S (S<101)毫升 (正好装满一瓶) ,它们三个之间可以相互倒可乐 (都是没有刻度的,且 S==N+M,101>S>0,N>0,M>0) 。聪明的ACMER你们说他们能平分吗?如果能请输出倒可乐的最少的次数,如果不能输出"NO"。
 
  直接BFS就好,100*100*100种状态,还是不会超。。。。。。(还有更好的方法吗?)
 
代码如下:
#include<iostream>
#include<cstring> using namespace std; int que[],las,fir;
int A,B,C;
long long vis[][][]; bool judge(int x,int y,int z)
{
if(vis[x][y][z]==-)
return ;
return ;
} long long slove()
{
int temp,t1,t2,t3;
int base; las=fir=;
memset(vis,-,sizeof(vis)); que[las++]=A**+*+;
vis[A][][]=; while(las-fir)
{
temp=que[fir++]; t1=temp/(*);
t2=(temp/)%;
t3=temp%;
base=vis[t1][t2][t3];
if((t1==A/&&(t2==A/||t3==A/))||(t2==A/&&t3==A/))
return base; temp=min(t1,B-t2);
t1-=temp;
t2+=temp;
if(judge(t1,t2,t3))
{
vis[t1][t2][t3]=base+;
que[las++]=t1*(*)+t2*+t3;
}
t1+=temp;
t2-=temp; temp=min(t1,C-t3);
t1-=temp;
t3+=temp;
if(judge(t1,t2,t3))
{
vis[t1][t2][t3]=base+;
que[las++]=t1*(*)+t2*+t3;
}
t1+=temp;
t3-=temp; temp=min(t2,A-t1);
t2-=temp;
t1+=temp;
if(judge(t1,t2,t3))
{
vis[t1][t2][t3]=base+;
que[las++]=t1*(*)+t2*+t3;
}
t2+=temp;
t1-=temp; temp=min(t2,C-t3);
t2-=temp;
t3+=temp;
if(judge(t1,t2,t3))
{
vis[t1][t2][t3]=base+;
que[las++]=t1*(*)+t2*+t3;
}
t2+=temp;
t3-=temp; temp=min(t3,A-t1);
t3-=temp;
t1+=temp;
if(judge(t1,t2,t3))
{
vis[t1][t2][t3]=base+;
que[las++]=t1*(*)+t2*+t3;
}
t3+=temp;
t1-=temp; temp=min(t3,B-t2);
t3-=temp;
t2+=temp;
if(judge(t1,t2,t3))
{
vis[t1][t2][t3]=base+;
que[las++]=t1*(*)+t2*+t3;
}
t3+=temp;
t2-=temp;
} return -;
} int main()
{
ios::sync_with_stdio(false); long long ans; for(cin>>A>>B>>C;A+B+C;cin>>A>>B>>C)
{
if(A%)
ans=-;
else
ans=slove(); if(ans!=-)
cout<<ans<<endl;
else
cout<<"NO\n";
} return ;
}

(中等) HDU 1495 非常可乐,BFS。的更多相关文章

  1. HDU 1495 非常可乐 BFS 搜索

    http://acm.hdu.edu.cn/showproblem.php?pid=1495 题目就不说了, 说说思路! 倒可乐 无非有6种情况: 1. S 向 M 倒 2. S 向 N 倒 3. N ...

  2. HDU 1495 非常可乐 bfs 难度:1

    http://acm.hdu.edu.cn/showproblem.php?pid=1495 第三个杯子的盛水量可由前两个杯子得到,而前两个杯子状态总数在100*100以内,穷举可实现 #includ ...

  3. (step4.2.5)hdu 1495(非常可乐——BFS)

    题目大意:输入三个整数 a,b,c.   a : 可乐瓶的容量,b: 甲杯的容量 ,c: 乙杯的容量.问能否用这三个被来实现饮料的平分???如果可以输出倒饮料的次数, 否则输出NO 解题思路:BFS ...

  4. HDU 1495 非常可乐 BFS搜索

    题意:有个为三个杯子(杯子没有刻度),体积为s,n,m,s=m+n, 刚开始只有体积为s的杯子装满可乐,可以互相倒,问你最少的次数使可乐均分,如果没有结果,输出-1; 分析:直接互相倒就完了,BFS模 ...

  5. HDU 1495 非常可乐 BFS

    题目大意:中文题不说了. 题目思路:我有同学用GCD数论写出来的代码很简洁,但是很抱歉,数论蒟蒻,我觉得比赛的时候我没办法推出.如果用BFS的话思路很简单的,就是6方向广搜,只不过稍微麻烦点.具体看代 ...

  6. HDU - 1495 非常可乐 bfs互倒三杯水

    非常可乐 Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)Total Submis ...

  7. BFS(倒水问题) HDU 1495 非常可乐

    题目传送门 /* BFS:倒水问题,当C是奇数时无解.一共有六种情况,只要条件符合就入队,我在当该状态vised时写了continue 结果找了半天才发现bug,泪流满面....(网上找份好看的题解都 ...

  8. HDU 1495 非常可乐(数论,BFS)

    非常可乐 Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others) Total Submi ...

  9. 非常可乐---hdu 1495(BFS)

    http://acm.hdu.edu.cn/showproblem.php?pid=1495 题意: 有3个杯子a b c:a=b+c:然后刚开始时只有a是满的,其它为空的,然后a b c三个之间互相 ...

随机推荐

  1. white-space详解

    white-space共有5种属性normal,nowrap,pre,pre-wrap,pre-line 网上的解释多半过于详细冗长,先做个简化处理,以便查询 normal    忽略空白  过长换行 ...

  2. iOS 开发之照片框架详解之二 —— PhotoKit 详解(下)

    本文链接:http://kayosite.com/ios-development-and-detail-of-photo-framework-part-three.html 这里接着前文<iOS ...

  3. 一个完整的项目中,需要的基本gulp

    一个完整的项目需要使用gulp的多种功能,包括—— (1)加载各种需要的插件 var concat=require('gulp'); var clean=require(''gulp); 等等.需要的 ...

  4. mplayer最全的命令

    前段时间做过qt内嵌mplayer的一个小程序,感觉mplayer还行不过不支持打开图片感觉有点无力.话不多说上代码: QString path="d:/1.mkv"; QWidg ...

  5. android 原生的DownloadManager

    代码: public class MainActivity extends Activity { private DownloadManager downloadManager; public sta ...

  6. Java 垃圾回收机制学习

    原文链接: http://blog.csdn.net/zsuguangh/article/details/6429592 自己学习总结: 1c++和java的内存使用的区别: 在C++中,对象所占的内 ...

  7. C#无边框窗体移动 将事件绑定到想实现的控件上

    [DllImport("user32.dll")] public static extern bool ReleaseCapture(); [DllImport("use ...

  8. angularjs ng-switch

    <p> <a href="#" ng-click="toggle()">Toggle Section</a> </p& ...

  9. iOS对UIViewController生命周期和属性方法的解析

    目录[-] iOS对UIViewController生命周期和属性方法的解析 一.引言 二.UIViewController的生命周期 三.从storyBoard加载UIViewController实 ...

  10. vim的复制粘贴小结(转)

    原文地址:http://lsong17.spaces.live.com/blog/cns!556C21919D77FB59!603.entry 内容: 用vim这么久 了,始终也不知道怎么在vim中使 ...