(中等) HDU 1495 非常可乐,BFS。
Description
#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。的更多相关文章
- HDU 1495 非常可乐 BFS 搜索
http://acm.hdu.edu.cn/showproblem.php?pid=1495 题目就不说了, 说说思路! 倒可乐 无非有6种情况: 1. S 向 M 倒 2. S 向 N 倒 3. N ...
- HDU 1495 非常可乐 bfs 难度:1
http://acm.hdu.edu.cn/showproblem.php?pid=1495 第三个杯子的盛水量可由前两个杯子得到,而前两个杯子状态总数在100*100以内,穷举可实现 #includ ...
- (step4.2.5)hdu 1495(非常可乐——BFS)
题目大意:输入三个整数 a,b,c. a : 可乐瓶的容量,b: 甲杯的容量 ,c: 乙杯的容量.问能否用这三个被来实现饮料的平分???如果可以输出倒饮料的次数, 否则输出NO 解题思路:BFS ...
- HDU 1495 非常可乐 BFS搜索
题意:有个为三个杯子(杯子没有刻度),体积为s,n,m,s=m+n, 刚开始只有体积为s的杯子装满可乐,可以互相倒,问你最少的次数使可乐均分,如果没有结果,输出-1; 分析:直接互相倒就完了,BFS模 ...
- HDU 1495 非常可乐 BFS
题目大意:中文题不说了. 题目思路:我有同学用GCD数论写出来的代码很简洁,但是很抱歉,数论蒟蒻,我觉得比赛的时候我没办法推出.如果用BFS的话思路很简单的,就是6方向广搜,只不过稍微麻烦点.具体看代 ...
- HDU - 1495 非常可乐 bfs互倒三杯水
非常可乐 Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)Total Submis ...
- BFS(倒水问题) HDU 1495 非常可乐
题目传送门 /* BFS:倒水问题,当C是奇数时无解.一共有六种情况,只要条件符合就入队,我在当该状态vised时写了continue 结果找了半天才发现bug,泪流满面....(网上找份好看的题解都 ...
- HDU 1495 非常可乐(数论,BFS)
非常可乐 Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others) Total Submi ...
- 非常可乐---hdu 1495(BFS)
http://acm.hdu.edu.cn/showproblem.php?pid=1495 题意: 有3个杯子a b c:a=b+c:然后刚开始时只有a是满的,其它为空的,然后a b c三个之间互相 ...
随机推荐
- 扫描局域网内的ip和主机名
1. 目的 今天发现我配置的一台电脑ip被人占用了,所以准备写个程序扫描一下局域网内所有正在使用的ip和主机名 2. 实现--直接上代码 import time import threading im ...
- JNI调用问题(部分机型崩溃)
1.今日测试发现在部分手机上游戏会崩溃,通过logcat日志发现是jni调用问题(我猜测) 错误日志中有如下语句: trying to work around app JNI bugs, but di ...
- List、Set、Map集合存放null解析及HashMap、Hashtable异同点解析
1.List.Set.Map集合存放null解析: @Test public void CollectionTest() { // 测试List List<Object> list = n ...
- iOS 多语言 浅析
什么是本地化处理? 本地化处理就是我们的应用程序有可能发布到世界的很多国家去,因为每个国家应用的语言是不一样的,所以我们要把我们的应用程序的语言要进行本地化处理一下. 本地化处理需要处理那些文件? ( ...
- arrayList里的快速失败
快速失败是指某个线程在迭代集合类的时候,不允许其他线程修改该集合类的内容,这样迭代器迭代出来的结果就会不准确. 比如用iterator迭代collection的时候,iterator就是另外起的一个线 ...
- Linux 下 git的使用
参考链接:http://www.liaoxuefeng.com 安装 安装步骤: ①先给操作系统装入git工具,以Linux为例: $ sudo apt-get install git ②去githu ...
- L2,breakfast or lunch
express: what a day多么糟糕的天气 I‘m coming to see you我将要来看你 what a lot of trouble he is causing他犯了多少错误啊 w ...
- debug经验汇总
(1)使用pstack (2)调试core文件 # gdb ./segment core (3)使用strace strace -tt -f -s 1234 -o /tmp/strace.cwc -p ...
- 完美解决ie8以下不兼容h5的方法
HTML5的语义化标签以及属性,可以让开发者非常方便地实现清晰的web页面布局,加上CSS3的效果渲染,快速建立丰富灵活的web页面显得非常简单. HTML5的新标签元素有: <header&g ...
- 干货分享:MySQL之化险为夷的【钻石】抢购风暴【转载】
转自: 干货分享:MySQL之化险为夷的[钻石]抢购风暴 - Vanos_韩尛哲 - 博客园http://www.cnblogs.com/Vanos-lcp/p/5642097.html 抢购钻石不稀 ...