10603UVA倒水
来源:互联网 发布:日立n3000知乎 编辑:程序博客网 时间:2024/05/19 00:43
参考的例题写的刘汝佳,就是把每个状态遍历一遍
注意:
bool operator<(const st& rhs)const
{
return pour > rhs.pour;
}
#include<queue>#include<algorithm>using namespace std;#include<stdio.h>#include<string.h>struct st{int water[3];int pour;bool operator<(const st& rhs)const{return pour > rhs.pour;}};int vis[250][250];int ans[250];int cup[3];int wanted;int main(){//freopen("input.txt","r",stdin);int t;scanf("%d",&t);while(t--){scanf("%d%d%d%d",cup,cup+1,cup+2,&wanted);priority_queue<st> que;st temp;temp.water[0]=temp.water[1]=0;temp.water[2]=cup[2];temp.pour=0;que.push(temp);vis[0][0]=1;memset(ans,-1,sizeof(ans));memset(vis,0,sizeof(vis));while(!que.empty()){temp=que.top();que.pop();for(int i=0;i<3;i++){if(ans[temp.water[i]]==-1||temp.pour<ans[temp.water[i]])ans[temp.water[i]]=temp.pour;}int amount;st next;for(int i=0;i<3;i++){for(int j=0;j<3;j++){if(i!=j){amount=min(temp.water[i],cup[j]-temp.water[j]);memcpy(&next,&temp,sizeof(temp));next.water[i]-=amount;next.water[j]+=amount;next.pour+=amount;if(!vis[next.water[0]][next.water[1]]){que.push(next);vis[next.water[0]][next.water[1]]=1;}}}}}int d=wanted;while(ans[d]==-1)d--;printf("%d %d\n",ans[d],d);}}
0 0
- uva 10603 倒水 bfs
- UVa 10603 倒水
- 10603UVA倒水
- uva 10603 倒水问题
- UVA 10603 Fill倒水问题
- 倒水问题(Fill,UVa 10603)
- 倒水问题(Fill,UVa 10603)
- uva 10603 Fill(倒水问题 BFS)
- Fill (Uva 10603 bfs 倒水问题)
- UVA 10603 Fill(倒水问题)
- Uva 倒水问题
- UVa 10603 - Fill,经典倒水问题+隐式图搜索+dfs
- uva 10603倒水问题(搜索 隐式图的最短路 )
- 例题7-8 UVA 10603 Fill 倒水问题
- UVA 10603 Fill(状态空间搜索,倒水问题)
- UVA-10603 Fill 倒水问题 BFS+优先队列
- uva 10603 三个杯子倒水问题 BFS搜索
- 例题7-8 倒水问题(Fill, UVa 10603)
- 观察者设计模式
- C语言宏的使用小结
- JDK API文档的使用
- 目标和学习方法的重要性
- Linux 网络分析工具之tcpdump
- 10603UVA倒水
- VS2008中导入EXCEL文件数据(Unicode版本下)
- Android 查看及设置 SELinux 状态
- Android之HelloWorld
- 在MFC对话框中显示html网页
- Android常用控件-ListView
- java基础学习API之Date,DateFormat和Calendar 六-4
- 安卓的系统架构(随笔)
- Java面试题-基本语法