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 Andimeo at 2008-10-18 02:20:09 on Problem 2969
In Reply To:需要注意的数据 Posted by:MIRKING at 2008-07-24 00:33:03
> 000 0
> 250 0
> 2500 0
> 5500 0
> 6350 630
> 77675 765
> 77570 7770
> 12345 43215
> 1234567890 9876543210
上述数据我全都过了,而且在川大的OJ上也交过了,为什么还是WA了
哪位指点一下啊,代码如下
#include<stdio.h>

#define in(a,b) (a<b?a:b)
#define ax(a,b) (a>b?a:b)

char s[1000+4];

int num[10];
int print[10];

bool ok;
bool tail5;
void process(void)
{
	int num5 = num[2]+num[5]+num[8];
	int num10 = num[1]+num[4]+num[7];
	int num0 = num[3]+num[6]+num[9];
	if(num[0])
	{
		ok=true;
		tail5=false;
		print[9]=num[9];
		print[6]=num[6];
		print[3]=num[3];
		if(num5>=1&&num10>=1 || num0>0)
		{
			print[0]=num[0];//如果末尾是5满足条件,是0一样满足条件
			//.....
			int min5;
			int min10;
			if((num5*5+num10*10)%15==0)
			{
				min5=num5;
				min10=num10;
			}
			else if((num5*5+num10*10)%15==5)
			{
				if(num5>=1)
				{
					min5=num5-1;
					min10=num10;
				}
				else if(num10>=2)
				{
					min5=num5;
					min10=num10-2;
				}
				else
				{
					min5=0;
					min10=0;
				}
			}
			else
			{
				if(num10>=1)
				{
					min5=num5;
					min10=num10-1;
				}
				else if(num5>=2)
				{
					min5=num5-2;
					min10=num10;
				}
				else
				{
					min5=0;
					min10=0;
				}
			}
			if(min5==0&&min10==0&&num0==0)
			{
				print[0]=1;
				return;
			}
			////////////////////////////////////
				if(num[8]<=min5)
				{
					print[8]+=num[8];min5-=num[8];
					num[8]=0;
					
				}
				else
				{
					print[8]+=min5;
					num[8]=num[8]-min5;
					min5-=min5;
				}
				if(num[5]<=min5)
				{
					print[5]+=num[5];min5-=num[5];
					num[5]=0;
					
				}
				else
				{
					print[5]+=min5;
					num[5]=num[5]-min5;
					min5-=min5;
				}
				if(num[2]<=min5)
				{
					print[2]+=num[2];min5-=num[2];
					num[2]=0;
					
				}
				else
				{
					print[2]+=min5;
					num[2]-=min5;
					min5-=min5;
				}
			///////////////////////////////////////
				if(num[7]<=min10)
				{
					print[7]+=num[7];	min10-=num[7];
					num[7]=0;
				
				}
				else
				{
					print[7]+=min10;
					num[7]-=min10;
					min10=0;
				}
				if(num[4]<=min10)
				{
					print[4]+=num[4];min10-=num[4];
					num[4]=0;
					
				}
				else
				{
					print[4]+=min10;
					num[4]-=min10;
					min10=0;
				}
				if(num[1]<=min10)
				{
					print[1]+=num[1];min10-=num[1];
					num[1]=0;
					
				}
				else
				{
					print[1]+=min10;
					num[1]-=min10;
					min10=0;
				}
		}
		else
		{
			print[0]=1;
		}
	}
	else
	{
		tail5=true;
		num[5]--;
		num5--;
		print[9]=num[9];
		print[6]=num[6];
		print[3]=num[3];
		if(num10>=1||num5>=2)
		{
			ok=true;
			//......
			int min5,min10;
			min5=num5;
			min10=num10;
			if((num5*5+num10*10)%15==0)
			{
				if(min5>=1)
				{
					min5--;
				}
				else if(min10>=2)
				{
					min10-=2;
				}
				else
				{
					min5=0;
					min10=0;
				}
			}
			else if((num5*5+num10*10)%15==5)
			{
				if(min10>=1)
					min10--;
				else if(min5>=2)
				{
					min5-=2;
				}
				else
				{
					min10=0;
					min5=0;
				}
			}
			if(min10==0&&min5==0)
			{
				ok=false;
				return;
			}
			////////////////////////////////////
				if(num[8]<=min5)
				{
					print[8]+=num[8];min5-=num[8];
					num[8]=0;
					
				}
				else
				{
					print[8]+=min5;
					num[8]=num[8]-min5;
					min5-=min5;
				}
				if(num[5]<=min5)
				{
					print[5]+=num[5];min5-=num[5];
					num[5]=0;
					
				}
				else
				{
					print[5]+=min5;
					num[5]=num[5]-min5;
					min5-=min5;
				}
				if(num[2]<=min5)
				{
					print[2]+=num[2];min5-=num[2];
					num[2]=0;
					
				}
				else
				{
					print[2]+=min5;
					num[2]-=min5;
					min5-=min5;
				}
			///////////////////////////////////////
				if(num[7]<=min10)
				{
					print[7]+=num[7];min10-=num[7];
					num[7]=0;
					
				}
				else
				{
					print[7]+=min10;
					num[7]-=min10;
					min10=0;
				}
				if(num[4]<=min10)
				{
					print[4]+=num[4];min10-=num[4];
					num[4]=0;
					
				}
				else
				{
					print[4]+=min10;
					num[4]-=min10;
					min10=0;
				}
				if(num[1]<=min10)
				{
					print[1]+=num[1];min10-=num[1];
					num[1]=0;
					
				}
				else
				{
					print[1]+=min10;
					num[1]-=min10;
					min10=0;
				}

		}
		else
		{
			ok = false;
		}
	}
}

int main(void)
{
	while(gets(s)!=NULL)
	{
		int i,j;
		ok=false;
		tail5=false;
		for(i=0;i<10;i++)
			print[i]=num[i]=0;
		for(i=0;s[i]!='\0';i++)
			num[s[i]-'0']++;
		if(!num[0]&&!num[5])
			printf("impossible\n");
		else
		{
			process();
			if(ok)
			{
				for(i=9;i>=0;i--)
				{
					for(j=0;j<print[i];j++)
					{
						putchar(i+'0');
					}
				}
				if(tail5)
					putchar('5');
				puts("");
			}
			else
				printf("impossible\n");
		}
	}
	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