题目链接:https://cn.vjudge.net/contest/281037#problem/A

题目大意:给你a,b,n。a代表第一个杯子的容量,b代表第二个杯子的容量,然后一共有6种操作。让你用尽可能少的步骤将第二个杯子的当前的水的体积转换成n。

具体思路:就是队列模拟啊,,,,打比赛的时候脑子瓦特了,没读完题目就开始读了,,,这个毛病确实得改了,,

AC代码:

 #include<iostream>
#include<stack>
#include<iomanip>
#include<cmath>
#include<stdio.h>
#include<cstring>
#include<algorithm>
#include<queue>
#include<vector>
using namespace std;
# define ll long long
const int maxn = 2e6+;
int head[maxn];
struct node
{
int op;
int a;
int b;
} q[maxn];
int ans[maxn],flag=;
int vis[+][+];
void print(int t)
{
if(t>)
{
print(head[t]);
ans[++flag]=q[t].op;
}
}
void cal(int t1,int t2,int g)
{
head[]=-;
int l=,r=,tt;
int num=;
q[].a=,q[].b=,q[].op=;
vis[][]=;
while(l<=r)
{
int tmp=l;
vis[q[tmp].a][q[tmp].b]=;
l++;
if(vis[t1][q[tmp].b]==){
head[++r]=tmp;
q[r].a=t1;
q[r].b=q[tmp].b;
q[r].op=;
if(q[r].b==g)
{
print(r);
return ;
}
}
if(vis[q[tmp].a][t2]==)
{
head[++r]
=tmp;
q[r].a=q[tmp].a;
q[r].b=t2;
q[r].op=;
if(q[r].b==g)
{
print(r);
return ;
}
}
if(vis[][q[tmp].b]==)
{
head[++r]
=tmp;
q[r].a=;
q[r].b=q[tmp].b;
q[r].op=;
if(q[r].b==g)
{
print(r);
return ;
}
}
if(vis[q[tmp].a][]==)
{
head[++r]
=tmp;
q[r].a=q[tmp].a;
q[r].b=;
q[r].op=;
if(q[r].b==g)
{
print(r);
return ;
}
}
int s1=q[tmp].a-min(q[tmp].a,t2-q[tmp].b);
int s2=q[tmp].b+q[tmp].a-s1;
if(vis[s1][s2]==)
{
head[++r]
=tmp;
q[r].a=s1;
q[r].b=s2;
q[r].op=;
if(q[r].b==g)
{
print(r);
return ;
}
}
s1=q[tmp].b-min(q[tmp].b,t1-q[tmp].a);
s2=q[tmp].a+q[tmp].b-s1;
if(vis[s1][s2]==)
{
head[++r]
=tmp;
tt=q[tmp].b;
q[r].b=s1;
q[r].a=s2;
q[r].op=;
if(q[r].b==g)
{
print(r);
return ;
}
}
}
}
int main()
{
int t1,t2,n;
while(~scanf("%d %d %d",&t1,&t2,&n))
{
memset(vis,,sizeof(vis));
flag=;
cal(t1,t2,n);
for(int i=; i<=flag; i++)
{
if(ans[i]==)
{
printf("fill A\n");
}
else if(ans[i]==)
{
printf("fill B\n");
}
else if(ans[i]==)
{
printf("empty A\n");
}
else if(ans[i]==)
{
printf("empty B\n");
}
else if(ans[i]==)
{
printf("pour A B\n");
}
else if(ans[i]==)
{
printf("pour B A\n");
}
}
printf("success\n");
}
// }
return ;
}

最新文章

  1. 深入理解客户区尺寸client
  2. 廖雪峰js教程笔记14 file文件操作
  3. Html5前端框架
  4. Failed to upgrade AX 2012 R3 Retail channel database from CU9 to CU11 if SQL Server version was lower than 2012
  5. C语言 const常量讲解
  6. 10.10 dos实验
  7. ASP.NET UpdatePanel实现点击按钮无刷新且执行js脚本
  8. 初探swift语言的学习笔记(闭包 - 匿名函数或block块代码)
  9. 一步一步学Vue(十二)
  10. 转: 【Java并发编程】之十三:生产者—消费者模型(含代码)
  11. go实例之函数
  12. 织梦dedecms默认网站地图sitemap.html优化
  13. react-native android textinput显示不全的问题
  14. c语言实现:三子棋
  15. (转)SqlServer2008 数据库同步:发布、订阅
  16. 最小齐套回写MO工单组件数量错误 SQL
  17. 数据结构和Java集合
  18. 团体队列(UVa540)
  19. 1021 Deepest Root (25)(25 point(s))
  20. 使用 powerdesigner 将数据库表结构逆向工程生成对应的word文档

热门文章

  1. 常用校验码(奇偶校验码、海明校验码、CRC校验码)
  2. Arduino与Air800开发板使用UART通信:传输DHT22传感器数据
  3. ElasticSearch 2 (36) - 信息聚合系列之显著项
  4. [转]MySQL 数据库事务隔离级别
  5. pixi.js + three.js
  6. Codeforces 68D - Half-decay Tree
  7. [代码]--c#获取系统时间
  8. 【刷题】LOJ 6121 「网络流 24 题」孤岛营救问题
  9. 洛谷SP16549 QTREE6 - Query on a tree VI(LCT)
  10. Apache Storm从一端读取实时数据的原始流