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

谁能看看我程序哪里错了...

Posted by forgotten at 2006-03-30 18:23:44 on Problem 2740
In Reply To:有什么trick么。。 Posted by:forgotten at 2006-03-30 11:51:53
#include <stdio.h>
#include <string.h>

const int MaxM = 10;		//	max number of desks
const int MaxC = 30;		//	max number of books allowed to put on a desk
const int MaxN = 100;		//	max number of students
const int MaxR = 50;		//	max number of books requested by one student
const int MaxID = 100;		//	max ID number of the books

bool had[MaxM][MaxID];
int desk[MaxM][MaxC + 1], desk_op[MaxM], desk_ed[MaxM];
int wait[MaxN * MaxR], wait_size;
int inform[MaxN][MaxR], size[MaxN];
int m, c;

int GetBook(int book) {
	int cost = 0, placed, took, i;

	for (i = 0; i < m; i ++) {
		if (had[i][book]) {
			cost += i + 1;
			desk_op[i] = (desk_op[i] + 1) % c;
			had[i][book] = false;
			break;
		}
	}
	if (i == m) {
		cost += m + 1;
	}

	for (i = 0; i < m; i ++) {
		if (desk_op[i] == desk_ed[i]) continue;
		cost += i + 1;
		desk[i][desk_ed[i]] = book;
		desk_ed[i] = (desk_ed[i] + 1) % c;
		had[i][book] = true;
		placed = i;
		break;
	}
	if (i == m) {
		cost += m + 1;
		placed = i;
	}

	if (i != 0) {
		cost ++;
		desk_op[0] = (desk_op[0] + 1) % c;
		took = desk[0][desk_op[0]];
		had[0][took] = false;
		for (i = 1; i < m; i ++) {
			if (desk_op[i] == desk_ed[i]) continue;
			cost += i + 1;
			desk[i][desk_ed[i]] = took;
			desk_ed[i] = (desk_ed[i] + 1) % c;
			had[i][took] = true;
			break;
		}
		if (i == m) {
			cost += m + 1;
		}
	
		cost += placed + 1 + 1;
		if (placed != m) {
			desk_ed[placed] = (desk_ed[placed] + c - 1) % c;
			had[placed][book] = false;
		}
		desk[0][desk_ed[0]] = book;
		desk_ed[0] = (desk_ed[0] + 1) % c;
		had[0][book] = true;
	}

	return cost;
}

int main() {

	int n, pBook, res;
	bool flag;

	while (scanf("%d%d%d", &m, &c, &n) == 3 && (m || c || n)) {
		if (c == 0) m = 0;
		c ++;
		wait_size = 0;
		memset(desk, 0, sizeof(desk));
		memset(had, false, sizeof(had));
		memset(desk_op, 0, sizeof(desk_op));
		for (int i = 0; i < m; i ++) {
			desk_ed[i] = 1;
		}

		for (int i = 0; i < n; i ++) {
			scanf("%d", &size[i]);
			for (int j = 0; j < size[i]; j ++) {
				scanf("%d", &inform[i][j]);
			}
		}

		pBook = 0;
		do {
			flag = true;
			for (int i = 0; i < n; i ++) {
				if (size[i] <= pBook) continue;
				wait[wait_size++] = inform[i][pBook] - 1;
				flag = false;
			}
			pBook ++;
		} while (!flag);

		res = 0;
		for (int i = 0; i < wait_size; i ++) {
			res += GetBook(wait[i]);
		}

		printf("%d\n", res);
	}

	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