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

贴个一次编写,无调试,0msAC的代码

Posted by 1805180411 at 2012-08-04 13:09:26 on Problem 1129
#include<iostream>
#include<memory>
using namespace std;

int n;
int map[27][27];
int visited[27];
int color[27];

void init()
{
	char str[30];
	int i,j;
	for(i = 1;i <= n;i ++)
	{
		cin>>str;
		for(j = 2;j < strlen(str);j++)
		{
			map[i][str[j] - 'A'+1] = 1;
		}
	}
}

int computer()
{
	int i,j;
	memset(color,-1,sizeof(color));
	color[1] = 1;
	for(i = 1;i <= n;i++)
	{
		memset(visited,0,sizeof(visited));
		for(j = 1;j <= n;j++)
		{
			if(map[i][j] && color[j])
				visited[color[j]] = 1;
		}
		for(j = 1;j <= n;j++)
		{
			if(!visited[j])
				break;
		}
		color[i] = j;
	}
	int mmax = 0;
	for(i = 1;i <= n;i++)
	{
		if(mmax < color[i])
			mmax = color[i];
	}
	return mmax;
}

int main()
{
	
	while(cin>>n && n != 0)
	{
		memset(map,0,sizeof(map));
		init();
		int mmin = 27;
		mmin = computer();
		if(mmin == 1)
			cout<<"1 channel needed."<<endl;
		else
			cout<<mmin<<" channels needed."<<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