SDUT Pots 2780
来源:互联网 发布:access 导入excel sql 编辑:程序博客网 时间:2024/06/06 07:16
Pots
Time Limit: 1000ms Memory limit: 65536K 有疑问?点这里^_^
题目描述
You are given two pots, having the volume of A and B liters respectively. The following operations can be performed:
FILL(i) fill the pot i (1 ≤ i ≤ 2) from the tap;
DROP(i) empty the pot i to the drain;
POUR(i,j) pour from pot i to pot j; after this operation either the pot j is full (and there may be some water left in the pot i), or the pot i is empty (and all its contents have been moved to the pot j).
Write a program to find the shortest possible sequence of these operations that will yield exactly C liters of water in one of the pots.
输入
On the first and only line are the numbers A, B, and C. These are all integers in the range from 1 to 100 and C≤max(A,B).
输出
The first line of the output must contain the length of the sequence of operations K. If the desired result can’t be achieved, the first and only line of the file must contain the word ‘impossible’.
示例输入
3 5 4
示例输出
6
#include <iostream>#include <stdio.h>#include <stdlib.h>#include <string.h>using namespace std;struct node{ int x,y; int sum;} q[200000];int b[1001][1001];int n,m,v;void bfs(){ int k=0,l=0; memset(b,0,sizeof(b)); b[0][0]=1; struct node t,r; int i; t.x=0; t.y=0; t.sum=0; q[l++]=t; while(k<l) { t=q[k++]; if(t.x==v || t.y==v) { printf("%d\n",t.sum); return ; } for(i=0; i<6; i++) { if(i==0) { r.x=n; r.y=t.y; } if(i==1) { r.x=t.x; r.y=m; } if(i==2) { r.y = t.x + t.y; if(r.y>=m) { r.x=r.y-m; r.y=m; } else r.x=0; } if(i==3) { r.x=t.y+t.x; if(r.x>=n) { r.y=r.x-n; r.x=n; } else r.y=0; } if(i==4) { r.x=0; r.y=t.y; } if (i==5) { r.x=t.x; r.y=0; } if(b[r.x][r.y]==0) { r.sum=t.sum+1; q[l++]=r; b[r.x][r.y]=1; } } } printf("impossible\n");}int main(){ while(scanf("%d%d%d",&n,&m,&v)!=EOF) { bfs(); } return 0;}
0 0
- SDUT-2780--Pots
- SDUT Pots 2780
- SDUT 2780 Pots BFS
- SDUT-2780 Pots(BFS)
- POJ 3414 Pots(BFS)||SDUT(Pots)
- SDUT--Pots(二维BFS)
- SDUTOJ【2780】 pots---bfs
- Pots
- Pots
- Pots
- Pots
- Pots
- Pots
- pots
- pots
- Pots
- Pots
- Pots
- 『IOS』Xcode工程中 添加AFNetworking出错_SecCertificateCreateWithData _SecTrustGetCertificateCount
- 插入排序-参考MoreWindows
- 【第四回】新手入门OCCT的一条学习主干线
- JAVA反射机制
- ubuntu编译qt5.3 WebKit
- SDUT Pots 2780
- CSS样式实践篇
- 自定义控件或布局如何传属性值
- Javascript 面向对象编程(一):封装
- POJ1009
- SAP CRM IPC
- 输出1到最大的N位数
- java transient的作用及使用方法
- Viewpager嵌套滑动冲突解决办法