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 Staryin at 2008-09-24 13:52:46 on Problem 1270
#include <iostream>
#include <vector>
#define oo 1000000
using namespace std;

char str[60];
char rel[200];
char *p;
int map[30][30];
int into[30];
char ele[30];
int cnt;
char ans[30];

void init()
{
	cnt=0;
	memset(map,0,sizeof(map));
	memset(into,0,sizeof(into));
	memset(ele,0,sizeof(ele));
}

void dfs(int pos)
{
	if(pos==cnt)
	{
		ans[pos]='\0';
		cout<<ans<<endl;
		return;	
	}
	vector<int> v;
	v.clear();
	for(int k=0;k<cnt;k++)
	{
		char a = ele[k];
		if(into[a-'a'] == 0)
		{
			//cout<<"a:"<<a<<"pos"<<pos<<endl;
			ans[pos] = a;
			for(int i=0;i<30;i++)
			if(map[a-'a'][i] == 1)
			{
				into[i]--;	
				v.push_back(i);
			}
			into[a-'a']=oo;
			
			dfs(pos+1);
			
			while(v.empty()==false)
			{
				int index = v.back();
				into[index]++;
				v.pop_back();
			}
			//if(map[a-'a'][i] == 0)into[i]++;
			into[a-'a']=0;
		}
		
	}	
	
}

int main()
{
	char a,b;
	while(cin.getline(str,50))
	{
		init();
		cin.getline(rel,200);
		p = strtok(str," ");
		if(p)ele[cnt++]=*p;
		p = strtok(NULL," ");
		while(p)
		{
			ele[cnt++]=*p;
			p = strtok(NULL," ");
		}
				
		p = strtok(rel," ");
		if(p) a = *p;
		p = strtok(NULL," ");
		if(p) b = *p;
		map[a-'a'][b-'a']=1;
		into[b-'a']++;
		p = strtok(NULL," "); 	
		
		while(p)
		{
			a = *p;
			p = strtok(NULL," ");
			b = *p;
			map[a-'a'][b-'a']=1;
			into[b-'a']++;
			p = strtok(NULL," ");
		}
		
		dfs(0);
		cout<<endl;
	}
	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