M - 非常可乐
#include<queue>
#include<stdio.h>
#include<string.h>
using namespace std; const int maxn = ;
const int oo = 0xfffffff; struct node{int cup[], step;};
node q;
int Full[];
int dir[][] = { {,},{,},{,},{,},{,},{,} };
int v[maxn][maxn][maxn]; void Turn(int &a, int &b, int FullB)//把瓶子a里面的水倒入瓶子B
{
if(a+b <= FullB)
b += a, a=;
else
{
a -= (FullB-b);
b = FullB;
}
}
int OK(node s)//判断是否已经分好
{
if(s.cup[]+s.cup[] == Full[] && s.cup[] == s.cup[])
return ;
if(s.cup[]+s.cup[] == Full[] && s.cup[] == s.cup[])
return ;
if(s.cup[]+s.cup[] == Full[] && s.cup[] == s.cup[])
return ; return ;
}
int Bfs(node s)
{
queue<node> Q;
Q.push(s); while(Q.size())
{
s = Q.front();Q.pop(); if(OK(s))
return s.step; for(int i=; i<; i++)
{
q = s;
Turn(q.cup[ dir[i][] ], q.cup[ dir[i][] ], Full[dir[i][]]); if(v[q.cup[]][q.cup[]][q.cup[]] == )
{
v[q.cup[]][q.cup[]][q.cup[]] = ;
q.step++;
Q.push(q);
}
}
} return -;
} int main()
{
node s; while(scanf("%d%d%d", &Full[], &Full[], &Full[]), Full[]+Full[]+Full[])
{
memset(v, , sizeof(v)); s.cup[] = Full[];
s.cup[]=s.cup[]=s.step=;
int ans = Bfs(s); if(ans == -)
printf("NO\n");
else
printf("%d\n", ans);
} return ;
}
M - 非常可乐的更多相关文章
- hdoj 1495 非常可乐【bfs隐式图】
非常可乐 Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)Total Submis ...
- HDU-1495 非常可乐(BFS)
广搜的灵活应用题: 非常可乐 Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others) T ...
- HDOJ 1495 非常可乐 【BFS】
非常可乐 Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others) Total Submi ...
- 非常可乐(bfs)
非常可乐 Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others) Total Submi ...
- HDU ACM 1495 非常可乐(广搜BFS)
非常可乐 Time Limit : 2000/1000ms (Java/Other) Memory Limit : 32768/32768K (Java/Other) Total Submissi ...
- HDU 1495 非常可乐(数论,BFS)
非常可乐 Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others) Total Submi ...
- 非常可乐(杭电hdu1495)bfs
非常可乐 Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others) Total Sub ...
- 题目1457:非常可乐(广度优先遍历BFS)
题目链接:http://ac.jobdu.com/problem.php?pid=1457 详解链接:https://github.com/zpfbuaa/JobduInCPlusPlus 参考代码: ...
- HDU1459 非常可乐(BFS) 2016-07-24 15:00 165人阅读 评论(0) 收藏
非常可乐 Problem Description 大家一定觉的运动以后喝可乐是一件很惬意的事情,但是seeyou却不这么认为.因为每次当seeyou买了可乐以后,阿牛就要求和seeyou一起分享这一瓶 ...
- HDU 1495 非常可乐 (只是转了个弯的广搜题)
N - 非常可乐 =========================================================================================== ...
随机推荐
- 类 Array Arraylist List Hashtable Dictionary
总结C# 集合类 Array Arraylist List Hashtable Dictionary Stack Queue 我们用的比较多的非泛型集合类主要有 ArrayList类 和 HashT ...
- Deep Learning 学习随记(六)Linear Decoder 线性解码
线性解码器(Linear Decoder) 前面第一章提到稀疏自编码器(http://www.cnblogs.com/bzjia-blog/p/SparseAutoencoder.html)的三层网络 ...
- C# RSA
using System; using System.Security.Cryptography; using System.Text; class RSACSPSample { static voi ...
- A*算法深入
A*算法思想容易理解,但要想设计出好的A*算法,则必需要全面深入了解它.在本文章中接下来的内容中,将全面深入探讨该话题.如果对该算法还没有理解的话,则请先查阅上篇文章<A*算法入门>,然后 ...
- python内置字符串操作方法
1.capitalize() S.capitalize()->string 首字母大写,其余字母小写. str='A222aaA' str.capitalize()#首字母大写,其余字母小写. ...
- Python核心编程2第一章课后练习
1-1 在windows下的安装方法在网上下载python2.7直接安装到C盘1)在系统变量中找到path. 2)编辑path值,添加你安装的python路径,C:\Python27. 3)检验pyt ...
- windows下实现uboot的tftp下载功能
一.原理分析 带有uboot的开发板实际上充当的就是tftp客户端,而PC机扮演的角色就是tftp服务器端,而tftp下载功能实际上就是文件传输.tftp服务器可以建立在虚拟机linux下,也可以建立 ...
- c# appdomain
http://www.cnblogs.com/Terrylee/archive/2005/11/28/285809.html
- db2索引创建和删除
在表trpt_jv_rpt_log_td的tim列上创建索引 create index dw_rpt.irpt_jv_rpt_log_td_tim on dw_rpt.trpt_jv_rpt_log_ ...
- 如何给div加一个边框border样式
如何给div加一个边框样式? 对div盒子加一个边框样式很简单只需要使用border板块样式即可. 一.虚线与实线边框 边框虚线样式:dashed 边框实现样式:solid border:1px da ...