UVA10603Fill
来源:互联网 发布:淘宝美工是干嘛的 编辑:程序博客网 时间:2024/06/05 23:11
#include<cstdio>#include<cstdlib>#include<cstring>#include<vector>#include<queue>using namespace std;const int MAXN = 210;int a, b, c, d;struct Node{int v[3], dis;bool operator < (const Node& rhs) const {return dis > rhs.dis;}};int vis[MAXN][MAXN];int cup[3];int ans[MAXN];void update_ans(const Node& n) {for(int i = 0; i < 3; i++) {int d = n.v[i];if(ans[d] < 0 || ans[d] > n.dis) ans[d] = n.dis; }}void solve(int a, int b, int c, int d) {Node n0;cup[0] = a; cup[1] = b; cup[2] = c;n0.v[0] = n0.v[1] = 0; n0.v[2] = c; n0.dis = 0;update_ans(n0);priority_queue<Node> q;q.push(n0);vis[0][0] = 1; while(!q.empty()) { if(ans[d] >= 0) break; Node n = q.top(); q.pop(); update_ans(n); for(int i = 0; i < 3; i++) { for(int j = 0; j < 3; j++) { if(i != j) { if(n.v[i] == 0 || n.v[j] == cup[j]) continue; int amount = min(cup[j] - n.v[j], n.v[i]); Node n1; memcpy(&n1, &n, sizeof(n));n1.v[i] -= amount;n1.v[j] += amount;if(vis[n1.v[0]][n1.v[1]]) continue;vis[n1.v[0]][n1.v[1]] = true;n1.dis = n.dis + amount;q.push(n1); }}}}while(d >= 0) {if(ans[d] >= 0) { printf("%d %d\n", ans[d], d); return ;} d--;}}int main() {int T;scanf("%d", &T);while(T--) {memset(ans, -1, sizeof(ans));memset(vis, 0, sizeof(vis));scanf("%d%d%d%d", &a, &b, &c, &d);solve(a, b, c, d);}return 0;}/*22 3 4 296 97 199 62*/
阅读全文
0 0
- UVA10603Fill
- 测试系列-Charles抓包和Mock数据的方法
- 【华为机试】提取不重复的整数
- 2017.7.17-2017.7.23暑期集训阶段性总结
- 【HDU
- tensorflow生成随机数的操作 tf.random_normal & tf.random_uniform & tf.truncated_normal & tf.random_shuffle
- UVA10603Fill
- Python爬虫框架Scrapy学习二记——Scrapy开发环境配置
- jsonp跨域请求API接口[自己写接口]
- Linux 网卡驱动学习(四)(缓存描述符 Buffer Description)
- 二.Groovy的介绍
- maven配置
- HDU 4115 Eliminate the Conflict (2-SAT)
- IDEA远程调试mapreduce程序
- 198. House Robber