UVA 10603(p202)----Fill
来源:互联网 发布:电路图绘制软件protel 编辑:程序博客网 时间:2024/05/17 00:49
#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;}
0 0
- UVA 10603(p202)----Fill
- UVA 10603 Fill
- uva 10603 - Fill
- uva 10603 - Fill
- UVa 10603 - Fill
- uva 10603 - Fill bfs
- uva 10603 Fill
- UVA 10603 - Fill
- UVa 10603 - Fill
- UVa:10603 Fill
- uva 10603 Fill
- UVA 10603 - Fill BFS~
- UVa 10603 - Fill
- UVA 10603-Fill
- uva 10603 Fill
- uva 10603 Fill
- UVa 10603 Fill
- UVa - 10603 - Fill
- hibernate笔记: 关于懒加载和load()方法
- freeradius and jradius configuration
- 十一、Android_UiAutomator 报告查看
- android 编程小技巧(1)---超实用的LogUtil
- WebKit之chromium进程创建过程分析
- UVA 10603(p202)----Fill
- iOS数据持久化-sqlite3
- 友元
- 第七章 变形 trnasform
- VMware+CentOS+zookeeper+solr集群环境搭建_org.apache.solr.handler.dataimport.DataImportHandler
- adb install in windows7
- 第八章 动画基础 过渡 transition
- valgrind -callgrind 实例
- git简介(转)