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 zzb619 at 2013-07-16 13:41:49 on Problem 1416
#include <cstdio>
#include <iostream>
#include <cstring>
#include <cmath>
using namespace std;

int target,num,len,ans;
int cc[1100];
int ccc[1100];// answer
int sz;
bool rej;
int take(int L,int R)
{
	int n=num;
	n%=int(pow(10.0,len-L+1)+.5);
	R=len-R;
	while(R--)
		n/=10;
	return n;
}
void dfs(int f,int sum,int cnt[],int size)
{
	if(f==len)
	{
		if(sum>ans)
		{
			memcpy(ccc,cnt,sizeof(ccc));
			ans=sum;
			sz = size;
			rej=0;
			return ;
		}
		if(sum==ans)// special rule 3
			rej=1;
	}
	if(target==take(f+1,len))// special rule 1
	{
		int ss=sum+take(f+1,len);
		if(ss<=target)
		{
			cnt[size++]=take(f+1,len);
			dfs(len,ss,cnt,size);
			cnt[--size]=0;
		}
		return ;
	}
	for(int i=1;i<=len-f;++i)
	{
		int ss=sum+take(f+1,f+i);
		if(ss<=target)
		{
			cnt[size++]=take(f+1,f+i);
			dfs(f+i,ss,cnt,size);
			cnt[--size]=0;
		}
	}
	return ;
}
int main()
{
	int getlen(int);
	while(~scanf("%d%d",&target,&num)&&target+num)
	{
		ans=-1;
		len=getlen(num);
		memset(cc,0,sizeof(cc));
		sz=0;
		rej=0;
		dfs(0,0,cc,0);
		if(ans==-1)
			printf("error\n");
		else if(rej)
			printf("rejected\n");
		else 
		{
			printf("%d ",ans);
			for(int i=0;i<sz;++i)
				printf("%d ",ccc[i]);// there's ' '于每一行结尾
			printf("\n");
		}
	}
	return 0;
}
int getlen(int num)
{
	int len=0;
	while(num)
	{
		num/=10;
		len++;
	}
	return len;
}

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