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 me at 2005-07-05 17:21:10 on Problem 1014
In Reply To:这样做可以吗??? Posted by:me at 2005-07-05 17:17:04
#include<stdio.h>

void outn(long k)
{
	printf("Collection #%ld:\nCan't be divided.\n\n",k);
}

void outy(long k)
{
	printf("Collection #%ld:\nCan be divided.\n\n",k);
}

long make(long a[],long a1[],long a2[])
{
	long n1=0,n2=0,i,t;

	for(i=1;i<7;i++)a1[i]=a2[i]=0;
	for(i=6;i;i--)
		if(a[i])
			if(n1>n2)
			{
				t=(n1-n2)/i;
				if(t>a[i])t=a[i];
				a2[i]=t;
				a[i]-=t;
				a2[i]+=(a[i]+1)/2;
				a1[i]=a[i]/2;
				n1+=a1[i]*i;
				n2+=a2[i]*i;
			}
			else
			{
				t=(n2-n1)/i;
				if(t>a[i])t=a[i];
				a1[i]=t;
				a[i]-=t;
				a1[i]+=(a[i]+1)/2;
				a2[i]=a[i]/2;
				n1+=a1[i]*i;
				n2+=a2[i]*i;
			}
	if(n1<n2)
	{
		for(i=1;i<7;i++)
		{t=a1[i];a1[i]=a2[i];a2[i]=t;}
		return n2-n1;
	}
	else return n1-n2;
}

int main()
{
	long a[7]={0},a1[7],a2[7],n=0,i,m,k=0;

	while(1)
	{
		k++;
		n=0;
		for(i=1;i<7;i++)
		{
			scanf("%ld",&a[i]);
			n+=a[i]*i;
		}
		if(!n)return 0;
		if(n%2){outn(k);continue;}
		n=make(a,a1,a2);
		if(n==6){outn(k);continue;}
		if(!n){outy(k);continue;}
		if(n==4)
		{
			m=0;
			for(i=6;i>2;i--)
				if(a1[i]>a2[i-2])m+=a2[i-2];
				else m+=a1[i];
				if(m){outy(k);continue;}
			m=0;
			for(i=6;i>2;i--)
				if(a1[i]>a2[i-1])m+=a2[i-1];
				else m+=a1[i];
				if(m>1){outy(k);continue;}
				else{outn(k);continue;}
		}
		m=0;
		for(i=6;i>1;i--)
			if(a1[i]>a2[i-1])m+=a2[i-1];
			else m+=a1[i];
		if(m)outy(k);
		else outn(k);
	}
	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