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 15211160230 at 2016-10-25 11:07:35 on Problem 2570
感觉很新奇啊,原来可以这样做
#include <stdio.h>
#include <memory.h>
#define MAXN 201
int G[MAXN][MAXN];
void Print(int n)
{	char s[27];
	int num=0,t=n;
	while(t)
	{	s[num++]=t%2+'0';
		t/=2;
	}
	s[num]='\0';
	for(int i=0;i<num;++i)
		if(s[i]=='1')	printf("%c",'a'+i);
	puts("");
}
int main()
{	int n,a,b,i,j,k;
	char s[27];
	while(~scanf("%d",&n)&&n)
	{	memset(G,0,sizeof(G));
		while(1)
		{	scanf("%d %d",&a,&b);
			if(!a&&!b)	break;
			scanf(" %s",s);
			for(i=0;s[i]!='\0';++i)
				G[a][b]=G[a][b]|(1<<(s[i]-'a')); 
		}
		for(k=1;k<=n;++k)
		{	for(i=1;i<=n;++i)
			{	if(!G[i][k])	continue;
				for(j=1;j<=n;++j)
				{	if(!G[k][j])	continue;
					G[i][j]|=(G[i][k]&G[k][j]);
				}
			}
		}
		while(1)
		{	scanf("%d %d",&a,&b);
			if(!a&&!b)	break;
			if(G[a][b])	Print(G[a][b]);	
			else		puts("-");	
		}
		puts("");
	}
	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