UVA 10603(p202)----Fill
2016-02-26 14:22
288 查看
#include<bits/stdc++.h> using namespace std; const int maxn=200+50; int ans[maxn]; int cap[3],t,a,b,c,d; int v[maxn][maxn]; struct point { int v[3],dist; bool operator < (const point& rhs) const { return rhs.dist<dist; } }; void update(point u) { for(int i=0; i<3; i++) if(ans[u.v[i]]<0||u.dist<ans[u.v[i]]) ans[u.v[i]]=u.dist; } void solve(int a,int b,int c,int d) { point start; memset(v,0,sizeof(v)); memset(ans,-1,sizeof(ans)); priority_queue<point> q; cap[0]=a; cap[1]=b; cap[2]=c; start.v[0]=0; start.v[1]=0; start.v[2]=c; start.dist=0; v[0][0]=1; q.push(start); while(!q.empty()) { point now=q.top(); q.pop(); update(now); if(ans[d]>=0) break; for(int i=0; i<3; i++) for(int j=0; j<3; j++) { if(i!=j) { if(now.v[i]==0||now.v[j]==cap[j]) continue; int sum=min(cap[j],now.v[i]+now.v[j])-now.v[j]; point next; memcpy(&next,&now,sizeof(now)); next.v[i]-=sum; next.v[j]+=sum; next.dist+=sum; if(!v[next.v[0]][next.v[1]]) { v[next.v[0]][next.v[1]]=1; q.push(next); } } } } while(d>=0) { if(ans[d]>=0) { printf("%d %d\n",ans[d],d); break; } d--; } } int main() { scanf("%d",&t); while(t--) { scanf("%d%d%d%d",&a,&b,&c,&d); solve(a,b,c,d); } return 0; }
相关文章推荐
- [leetcode] 210. Course Schedule II 解题报告
- 十一、Android_UiAutomator 报告查看
- linux命令之uname
- 共用体和枚举
- Css3:transform变形
- Servlet映射规则
- 如何成为一名优秀的全栈工程师
- 内涵段子05
- HDU 1010
- jquery.fileupload.js插件使用初探--单图片上传预览
- linux bus driver device
- 每天一个linux命令(1):ls命令
- SQL Server 2008 R2 事务与隔离级别实例
- 数组和指针
- hdoj1996汉诺塔VI(水题)
- Shiro - 关于session
- PHP设计模式之单例模式
- 十、Configurator API 详细介绍
- NYOJ 46-最少乘法次数(数论)
- bzoj3503 和谐矩阵