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

bfs不超时,不超空间,自己测都过了谁帮我看下,给组数据?

Posted by alpc07 at 2007-09-21 20:59:24 on Problem 2192
#include <stdio.h>
#include <string.h>

struct stteam{int n1,n3;char s[401];} team[10000];
int len1,len2,len3,h,e;
char s1[201],s2[201],s3[401],N;

int bfs()
{
	int i,j,lens;
	char ts3[401];
	memset(team,0,sizeof(team));
	strcpy(team[0].s,s3);
	h=e=0;
	while (h<=e)
	{
		if (team[h].n1==len1+1)
		{
			if (strcmp(team[h].s,s2)==0)
				return 1;
		}
		for (i=team[h].n3;i<=len3;i++)
		{
			if (team[h].s[i]==s1[team[h].n1])
			{
				lens=strlen(team[h].s)-1;
				for (j=0;j<i;j++)
				{
					ts3[j]=team[h].s[j];
				}
				for (j=i+1;j<=lens;j++)
				{
					ts3[j-1]=team[h].s[j];
				}
				ts3[lens]='\0';
				if (strnicmp(s2,ts3,i-1)!=0&&i-1>=0)  //可行性剪枝,去了交还WA
					continue;
				for (j=h+1;j<=e;j++)	//状态剪重,去了有可能超空间..
				{
					if (strcmp(ts3,team[j].s)==0)
						goto NEXT;
				}
				e++;
				team[e].n1=team[h].n1+1;
				team[e].n3=i;
				strcpy(team[e].s,ts3);
				//printf("%s\n",team[e].s);
			}
NEXT:;
		}
		h++;
	}
	return 0;
}

int main()
{
	int iN;
	//freopen("e:\\text.txt","r",stdin);
	scanf("%d",&N);
	for (iN=1;iN<=N;iN++)
	{
		scanf("%s %s %s",s1,s2,s3);
		len1=strlen(s1)-1;
		len2=strlen(s2)-1;
		len3=strlen(s3)-1;
		if (bfs())
			printf("Data set %d: yes\n",iN);
		else printf("Data set %d: no\n",iN);
	}
	return 0;
}


WA的快疯了.

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