| ||||||||||
| Online Judge | Problem Set | Authors | Online Contests | User | ||||||
|---|---|---|---|---|---|---|---|---|---|---|
| Web Board Home Page F.A.Qs Statistical Charts | Current Contest Past Contests Scheduled Contests Award Contest | |||||||||
Re:bfs 分析很重要In Reply To:bfs 分析很重要 Posted by:0712105003 at 2010-01-16 11:24:11 直接模拟就能搞定, 两个主要函数
int getStepAB(int A, int B, int C)
{
int steps = 0, b = 0;
bool come[N + 2] = {0};
while (true) {
if (A + b <= B) {
execCommand(FILL1);execCommand(POUR12);
steps += 2;
b += A;
if (b == C)
break;
if (come[b])
return -1;
come[b] = true;
} else {
execCommand(FILL1);execCommand(POUR12);
steps += 2;
int a = A - (B - b);
if (C == a)
break;
execCommand(DROP2);execCommand(POUR12);
steps += 2;
b = a;
if (come[b])
return -1;
come[b] = true;
}
}
return steps;
}
int getStepBA(int A, int B, int C)
{
int steps = 0, b = 0;
bool come[N + 2] = {0};
if (b == 0) {
execCommand(FILL2);
b = B;
steps = 1;
} else if (b == C) {
return 1;
}
while (true) {
if (A <= b) {
execCommand(POUR21);
steps += 1;
b -= A;
if (b == C)
break;
execCommand(DROP1);
steps += 1;
if (come[b])
return -1;
come[b] = true;
} else {
execCommand(POUR21);
int a = b;
b = 0;
execCommand(FILL2);
execCommand(POUR21);
b = B - (A - a);
steps += 3;
if (b == C)
break;
execCommand(DROP1);
steps += 1;
if (come[b])
return -1;
come[b] = true;
}
}
return steps;
}
Followed by: Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator