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 fzbzchenxi at 2007-07-28 08:52:15 on Problem 3211
现在找到的数据还没有错误,但是老WA,我这个题目做法是查找可能的的差值,最后最长时间为(总和+差值)/2,以下是代码,多谢了!
#include<stdio.h>
#include<memory.h>
#include<string.h>
struct node
{
	char color[20];
	int useti[100];
}clo[10];
int i,m,n,val,ans,t,use[100002],mid[100002];
char str[20];
bool get[100001];
int Findcolor()
{
	int i;
	for (i=0;i<m;i++)
		if (!strcmp(str,clo[i].color)) return i;
}
int oper(int x)
{
	int i,j,h,sum;
	if (clo[x].useti[0]==0) return 0;
	use[0]=1;use[1]=clo[x].useti[1];sum=use[1];
	for (i=2;i<=clo[x].useti[0];i++)
	{
		memset(get,false,sizeof(get));
		mid[0]=0;h=clo[x].useti[i];sum+=h;
		for (j=1;j<=use[0];j++)
		{
			if (!get[use[j]+h])
			{
				mid[++mid[0]]=use[j]+h;
				get[use[j]+h]=true;
			}
			if (use[j]>=h&&!get[use[j]-h])
			{
				mid[++mid[0]]=use[j]-h;
				get[use[j]-h]=true;
			}
			if (use[j]<h&&!get[h-use[j]])
			{
				mid[++mid[0]]=h-use[j];
				get[h-use[j]]=true;
			}
		}
		for (j=0;j<=mid[0];j++) use[j]=mid[j];
	}
	for (i=0;;i++) if (get[i]) break;
	return (sum+i)>>1;
}
int main()
{
	while (scanf("%d%d",&m,&n)&&(m||n))
	{
		for (i=0;i<m;i++)
		{
			scanf("%s",&clo[i].color);
			clo[i].useti[0]=0;
		}
		for (i=0;i<n;i++)
		{
			scanf("%d%s",&val,&str);
			t=Findcolor();
			clo[t].useti[++clo[t].useti[0]]=val;
		}
		ans=0;
		for (i=0;i<m;i++)
			ans+=oper(i);
		printf("%d\n",ans);
	}
	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