10603
来源:互联网 发布:微软软件license模式 编辑:程序博客网 时间:2024/06/11 18:49
Fill
UVA - 10603题意:给三个杯子,第1个第2个空,第三个装满水,每次操作是一个杯子向另一个杯子倒水直到其中一个杯子为空或者另一个杯子倒满,求使其中一个杯子最接近d的最小倒水流量
解:最短路;
#include <iostream>#include <bits/stdc++.h>using namespace std;const int N = 500;const int inf = 0x3f3f3f3f;const int maxn=1e6+2;typedef long long LL;struct node{ int v[4],cnt; bool operator <(const node &x)const { return cnt>x.cnt; }};int a, b, c, d;int vis[N][N], ans[N];void get(node x){ int cnt=x.cnt; if(ans[x.v[1]]==-1||ans[x.v[1]]>cnt) ans[x.v[1]]=cnt; if(ans[x.v[2]]==-1||ans[x.v[2]]>cnt) ans[x.v[2]]=cnt; if(ans[x.v[3]]==-1||ans[x.v[3]]>cnt) ans[x.v[3]]=cnt; return ;}void bfs(){ int cap[4]; cap[1]=a,cap[2]=b,cap[3]=c; memset(vis,0,sizeof(vis)); memset(ans,-1,sizeof(ans)); node s1; s1.cnt=0,s1.v[1]=0,s1.v[2]=0,s1.v[3]=c; vis[0][0]=1; priority_queue<node>q; q.push(s1); while(!q.empty()) { node tmp=q.top();q.pop(); get(tmp); if(ans[d]!=-1) { printf("%d %d\n",ans[d],d); return ; } for(int i=1;i<=3;i++) { if(tmp.v[i]==0) continue; for(int j=1;j<=3;j++) { if(i==j) continue; if(tmp.v[j]==cap[j]) continue; int mint=min(tmp.v[i],cap[j]-tmp.v[j]); node s2=tmp; s2.cnt+=mint,s2.v[i]-=mint,s2.v[j]+=mint; if(!vis[s2.v[1]][s2.v[2]])vis[s2.v[1]][s2.v[2]]=1, q.push(s2); } } } while(d>=0) { if(ans[d]!=-1) { printf("%d %d\n",ans[d],d); return ; } d--; }}int main(){ int t; scanf("%d", &t); while(t--) { scanf("%d %d %d %d", &a,&b,&c,&d); bfs(); } return 0;}
0 0
- 10603
- 10603 - Fill
- 10603 - Fill
- 10603 - Fill
- 10603 - Fill
- UVA 10603 Fill
- uva 10603 - Fill
- uva 10603 - Fill
- uva 10603 倒水 bfs
- UVa 10603 - Fill
- uva 10603 - Fill bfs
- uva 10603 Fill
- UVA 10603 - Fill
- UVa 10603 - Fill
- UVA 10603 (13.07.24)
- UVa:10603 Fill
- uva 10603 Fill
- UVA 10603 - Fill BFS~
- 关于导航栏透明和渐变的一些设置
- AndroidStudio打包出现"xxx" is not translated in "zh" (Chinese) [MissingTranslation]
- 一道简单而又不简单的面试题
- 在iOS中创建React-Native页面,并跳转到原生页面
- Android线程池的使用
- 10603
- vue引入 jquery 插件
- linux下关于mysql安装的一些问题
- Android studio 2.2 logcat 不打印log的问题
- -----------------------python&Tensorflow分割线------------------
- qt 之绘制 圆弧(抽奖圆盘)
- 机器学习算法之SVM(1)结构风险最小化
- Listview的基础使用
- 在react-native的项目中跳转到原生iOS页面