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

对拍了100组依旧WA。。。各种数据全过。。跪烂、、求数据。。附程序。。。

Posted by tank2game at 2012-10-04 14:59:51 on Problem 1239
//2次dp 做法还是挺难想的
# include<stdio.h>
# include<iostream>
# include<string.h>
# include<algorithm>
using namespace std;
int zero;
bool iszero;
char t;
int n;
int dp[100],f[100],ansf[100],maxf1;
char s[100];
char a[100],b[100];
int lena,lenb;
void st_copy(char *a,int left,int right,int &x)
{
	x=0;
	for(int i=left;i<=right;i++)
		a[x++]=s[i];
		return;
}
int compare_big(char *a,char *b)
{
	int firsta=0,firstb=0;
	while(firsta<lena&&a[firsta]=='0') firsta++;
		while(firstb<lenb&&b[firstb]=='0') firstb++;
		/*	if(lena-firsta!=lenb-firstb)
				return lena-firsta>lenb-firstb?1:-1;*/
			if(lena-firsta>lenb-firstb)
				return 1;
				else if(lena-firsta<lenb-firstb)
					return -1;
			for(;firsta<lena;firsta++,firstb++)
			{
				if(a[firsta]==b[firstb]) continue;
					return a[firsta]>b[firstb]?1:-1;
			}
			return 0;
}
int main()
{
	//freopen("in.txt","r",stdin);
	for(;;)
	{
		zero=0;n=0;
		iszero=true;
		while((t=getchar())&&(t<'0'||t>'9')) {}
		while((t>='0'&&t<='9'))
		{
			if(iszero&&t=='0')
			{
				zero++;
			}
			else
			{
				iszero=false;
				s[++n]=t;
			}
			t=getchar();
		}
		//printf("n:%d zero:%d\n",n,zero);
		if(n==0&&zero==1) {//printf("end\n");
			break;}
		dp[0]=0;
		for(int i=1;i<=n;i++)
		{
			dp[i]=0;
			for(int j=i-1;j>0;j--)
			{
				st_copy(a,j+1,i,lena);
				st_copy(b,dp[j]+1,j,lenb);
				//puts(a);puts(b);
				//bool t=;
				//printf("t:%d\n",t);
				if(compare_big(a,b)>0)
				{
					dp[i]=j;
					break;
				}
			}
			//printf("dp[%d]:%d\n",i,dp[i]);
		}
		maxf1=0;bool first=true;
		while(s[dp[n]+1]=='0'||first)
		{
			//printf("aaa");
			first=false;
		f[dp[n]+1]=n;
		for(int i=dp[n];i>=1;i--)
		{
			int j;
			if(i==dp[n]) j=dp[n];
				else j=f[i+1];
			for(;j>=i;j--)
			{
				st_copy(a,i,j,lena);
				st_copy(b,j+1,f[j+1],lenb);
				//puts(a);puts(b);
				int t=compare_big(a,b);
				//printf("i:%d j:%d t:%d\n",i,j,t);
				if(t<0)
				{
					f[i]=j;
					break;
				}
			}
			//printf("f[%d]:%d\n",i,f[i]);
		}
		//printf("dp[%d]:%d\n",n,dp[n]);
		if(f[1]>maxf1)
		{maxf1=f[1];
			for(int i=1;i<=n;i=f[i]+1)
				ansf[i]=f[i];
		}
		dp[n]--;
		}
	 	int temp;
		temp=1;
		for(int i=1;i<=zero;i++)
			printf("0");
		while(ansf[temp]!=n)
		{
			for(int i=temp;i<=ansf[temp];i++)
				printf("%c",s[i]);
			printf(",");
			temp=ansf[temp]+1;
		}
		for(int i=temp;i<=ansf[temp];i++)
				printf("%c",s[i]);
				printf("\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