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

终于ac了,暴搜给力~

Posted by 20142430131 at 2016-06-07 03:11:06 on Problem 1129
#include "stdio.h"
#include "stdlib.h"
#include "string.h"
#define Len sizeof(repeater)
struct repeater
{
	char c;
	repeater *next[25];
	int ch;
};
int main()
{
	int n;
	repeater *repm[26];
	char rep[27];
	scanf("%d", &n);
	while(n != 0)
	{
		memset(repm, NULL, 26);
		memset(rep, '0', 27);
		for (int i = 0; i < n; i ++)
		{
			repm[i] = (repeater *)malloc(Len);
			for (int j = 0; j < 25; j ++)
			{
				repm[i] ->next[j] = NULL;
			}
			repm[i] ->c = 65 + i;
			repm[i] ->ch = 1;
		}
		for (int i = 0; i < n; i ++)
		{
			if (i == 0)
				gets(rep);
			gets(rep);
			int t = strlen(rep);
			for (int j = 2; j < t; j ++)
			{
				int m = 0;
				while (repm[i] ->next[m] != NULL)
					m++;
				repm[i] ->next[m] = repm[rep[j] - 65];
			}
		}
		int chmax;
		for (int j = 0; j < n; j++)
		{
			int t = j;
			for (int i = 0; i < n; i ++)
			{
				int m = 0;	
				if (t >= n)
					t = t - n;
				while (repm[t] ->next[m] != NULL)
				{
					if (repm[t] ->next[m] ->ch == repm[t] ->ch)
					{
						repm[t] ->next[m] ->ch ++;
					}
					m ++;
				}
				t++;
			}
			t = j;
			for (int i = 0; i < n; i ++)
			{
				int m = 0;	
				if (t >= n)
					t = t - n;
				while (repm[t] ->next[m] != NULL)
				{
					if (repm[t] ->next[m] ->ch == repm[t] ->ch)
					{
						repm[t] ->next[m] ->ch ++;
					}
					m ++;
				}
				t++;
			}
			int tmax = 1;
			for (int i = 0; i < n; i ++)
			{
				if (repm[i] ->ch > tmax)
					tmax = repm[i] ->ch;
			}
			if (j == 0)
			 chmax = tmax;
			if (tmax < chmax )
				chmax =tmax;
			for (int i = 0; i < n; i ++)
				repm[i] ->ch = 1;
		}
		if (chmax == 1)
			printf("1 channel needed.\n");
		else
			printf("%d channels needed.\n", chmax);		
		scanf("%d", &n);
	}
	return 0;
}

两次循环是为了排除掉四个repeater两两相连的情况,亲测通过讨论里所有测试数据

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