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

大概就这个样子,用了一次Floyd.

Posted by xfxyjwf at 2005-07-11 22:07:58 on Problem 1087
In Reply To:这个题, 我郁闷了N天 Posted by:xfxyjwf at 2005-07-11 22:03:32
#include <stdio.h>
#include <string.h>

#define MAXA 100
#define MAXB 100
int cap[MAXA+1][MAXB+1];
int recept[MAXA+1],plug[MAXB+1],na,nb;

char str[4*MAXA+1][50];
int str_n;

int connect[4*MAXA+1][4*MAXA+1];

int Insert(const char ss[50])
{
	int i;
	for(i=1;i<=str_n;i++)
		if(strcmp(str[i],ss) == 0)
			break;
	if(i <= str_n)
		return i;
	strcpy(str[++str_n],ss);
	return str_n;
}

int main()
{
	int i,j,k;
	char ss[50],st[50];
	scanf("%d",&na);
	for(i=1;i<=na;i++)
	{
		scanf("%s",ss);
		recept[i] = Insert(ss);
	}
	scanf("%d",&nb);
	for(i=1;i<=nb;i++)
	{
		scanf("%s %s",st,ss);
		plug[i] = Insert(ss);
	}
	scanf("%d",&k);
	for(i=1;i<=k;i++)
	{
		scanf("%s %s",st,ss);
		connect[Insert(ss)][Insert(st)] = 1;
	}
	for(i=1;i<=str_n;i++)
		connect[i][i] = 1;
	for(k=1;k<=str_n;k++)
	{
		for(i=1;i<=str_n;i++)
		{
			if(!connect[i][k])	continue;
			for(j=1;j<=str_n;j++)
			{
				if(connect[k][j])
					connect[i][j] = 1;
			}
		}
	}
	for(i=1;i<=na;i++)
	{
		for(j=1;j<=nb;j++)
		{
			if(connect[recept[i]][plug[j]])
				cap[i][j] = 1;
		}
	}
}

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