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 !

Posted by bjss222 at 2007-07-09 23:03:38 on Problem 3211
#include<stdio.h>
#include<string.h>
#include<math.h>

const int N=100005;  
int m,n,cloth[10][105],t,c[15];
char col[12][15], ch[15];
int hh[N];

int min(int *a, int n){
    memset(hh, 0, sizeof(hh));
    int sum=0, mn=1234567,tag=0,i,j;
	for( i=0; i<n; i++){
		sum+=a[i]; tag++;  
		if(hh[a[i]]==0) hh[a[i]]=tag;
		for( j=0; j<=sum; j++) if(hh[j] && hh[j]!=tag && hh[a[i]+j]==0) hh[a[i]+j]=tag; 
	}
	for(i=0; i<=sum/2; i++) if(hh[i] && mn > sum-2*i) mn = sum-2*i; 
	return (mn+sum)/2;
}

int main(){
	while(scanf("%d%d",&m,&n),m||n){
		int i,j;
		memset(c, 0, sizeof(c));
		for(i=0; i<m; i++) scanf("%s", col[i]);
		for(i=0; i<n; i++){
			scanf("%d%s",&t, ch);
			for(j=0; j<m; j++) 	if(strcmp(ch, col[j])==0) cloth[j][c[j]++] = t;
		}
		int sum=0;
		for(i=0; i<n; i++)	if(c[i]) sum+=min(cloth[i],c[i]);
		printf("%d\n", sum);
	}
	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