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 fusion at 2006-12-03 20:23:55 on Problem 3128
#include <stdio.h>
#include <string.h>
#include <memory.h>


char s[27],r[27];
int used[27];


int Judge(int pos)
{
	if (pos>=26) return 1;
	if (r[pos]>='A'&&r[pos]<='Z') return Judge(pos+1);
	else
	{
		char kr[27],ch,tc;
		int kusd[27],i,tp;
		for (i=0;i<27;i++) kusd[i]=used[i];
		strcpy(kr,r);
		for (ch='A';ch<='Z';ch++)
		if (!used[ch-'A'])
		{
			tp=pos;tc=ch;
			while (1)
			{
				if (r[tp]>='A'&&r[tp]<='Z')
				{
					if (r[tp]==tc) break;
					else goto CONTINUE;
				}
				else if (used[tc-'A']) goto CONTINUE;
				r[tp]=tc;
				used[tc-'A']=1;
				tc=s[tp];
				tp=r[tp]-'A';
			}
			if (Judge(pos+1)) return 1;
			CONTINUE:
			strcpy(r,kr);
			for (i=0;i<27;i++) used[i]=kusd[i];
		}
	}
	return 0;
}


void read()
{
	int TestCase;
	scanf("%d",&TestCase);
	while (TestCase--)
	{
		memset(used,0,sizeof(used));
		memset(s,0,sizeof(s));
		memset(r,0,sizeof(r));
		scanf("%s",&s);
		if (Judge(0)) printf("Yes\n");
		else printf("No\n");
	}
}


int main()
{
	read();
	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