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

1.2kb代码供参考~

Posted by qddpx at 2012-08-11 23:41:33 on Problem 3414
#include <cstdio>
#include <cstring>
#define M 105

char vis[M][M], px[M][M], py[M][M], op[M][M], qx[M*M], qy[M*M];
int a, b, c, d[M][M], h, t;

void printop(char i) {
	char *s;
	if(i == 0)      s = "FILL(1)";
	else if(i == 1) s = "FILL(2)";
	else if(i == 2) s = "DROP(1)";
	else if(i == 3) s = "DROP(2)";
	else if(i == 4) s = "POUR(1,2)";
	else            s = "POUR(2,1)";
	printf("%s\n", s);
}

void push(int x, int y, int tx, int ty, int o) {
	if(!vis[x][y]) {
		qx[t] = x, qy[t++] = y;
		op[x][y] = o, d[x][y] = d[tx][ty] + 1;
		px[x][y] = tx, py[x][y] = ty, vis[x][y] = 1;
	}
}

void print(int x, int y) {
	if(d[x][y]) {
		print(px[x][y], py[x][y]);
		printop(op[x][y]);
	}
}

int main() {
	int x, y, tx, ty, td;
	scanf("%d%d%d", &a, &b, &c);
	memset(vis, 0, sizeof(vis));
	vis[0][0] = t = 1, d[0][0] = qx[0] = qy[0] = h = 0;
	while(h < t) {
		x = qx[h], y = qy[h];
		if(x == c || y == c) {
			printf("%d\n", d[x][y]);
			print(x, y);
			break;
		}
		h++;
		push(a, y, x, y, 0);
		push(x, b, x, y, 1);
		push(0, y, x, y, 2);
		push(x, 0, x, y, 3);
		td = (x < b-y) ? x : b-y;
		push(x-td, y+td, x, y, 4);
		td = (y < a-x) ? y : a-x;
		push(x+td, y-td, x, y, 5);
	}
	if(h >= t) printf("impossible\n");
	return 0;
}

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