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

WA 大牛帮帮忙!!!

Posted by XiaoS at 2008-09-26 23:53:16 on Problem 1323
#include <stdio.h>

int main()
{
	int m, n, p[51], i, j, q, count, k, t, amount = 1;

	while(scanf("%d %d", &m, &n)==2 && m){
		for(i=1; i<= n; i++)
			scanf("%d", &p[i]);
		for(i=n; i>1; i--)
			for(j=1; j<i; j++)
				if(p[j]>p[j+1]){
					t = p[j];
					p[j] = p[j+1];
					p[j+1] = t;
				}
	/*	for(i=1; i<=n; i++)
			printf("%d ", p[i]);  */
		q = m * n;
		i = n;
		count = 0;
		while(i){
			j = q - p[i];
			if(j >= i)
				break;
			k = 1;
			while((p[i]-p[i-1]) == 1){
				k ++;
				i --;
			}
			if(k-j > 0){
				count += (k-j);
				q = p[i] - 1;
				i --;
			}
			else{
				q = p[i] - (j-k);
				i -= (j-k+1);
			}
		}
		printf("Case %d: %d\n", amount++, count);
	}

	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