Online JudgeProblem SetAuthorsOnline ContestsUser
Web Board
Home Page
F.A.Qs
Statistical Charts
Problems
Submit Problem
Online Status
Prob.ID:
Register
Update your info
Authors ranklist
Current Contest
Past Contests
Scheduled Contests
Award Contest
User ID:
Password:
  Register

Re:bfs 分析很重要

Posted by gemenhao at 2010-01-28 11:35:53 on Problem 3414
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:
User ID:
Password:
Title:

Content:

Home Page   Go Back  To top


All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator