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 15211160230 at 2016-08-05 12:09:34 on Problem 2394
感觉好多人的代码风格好糟糕啊,我的应该还好吧
#include <stdio.h>
#include <limits.h>
#define MAXN 501
int G[MAXN][MAXN],vexnum;
int dis[MAXN];
void Initial(int N)
{	int i,j;
	for(i=0;i<=N;++i)
		for(j=0;j<=N;++j)
			G[i][j]=INT_MAX;
	vexnum=N;
}
int FindMin(int visited[])
{	int i,min=INT_MAX,k=-1;
	for(i=1;i<=vexnum;++i)
	{	if(visited[i]==1)	continue;
		if(dis[i]<min)
		{	min=dis[i];
			k=i;
		}
	}
	return k;
}
void Dijkstra(int k)
{	int visited[MAXN],i;
	for(i=1;i<=vexnum;++i)
		dis[i]=G[k][i],visited[i]=0;
	dis[k]=0,visited[k]=1;
	while(1)
	{	k=FindMin(visited);
		if(k==-1)	return;
		visited[k]=1;
		for(i=1;i<=vexnum;++i)
		{	if(visited[i]==1||G[k][i]==INT_MAX)		continue;
			if(dis[i]>dis[k]+G[k][i])
				dis[i]=dis[k]+G[k][i];
		}
	}
}
void Qsort(int s[],int left,int right)
{	if(left<right)
	{	int i=left,j=right,pivot=s[left];
		while(i<j)
		{	while(i<j&&s[j]>=pivot)		--j;
			if(i<j)		s[i++]=s[j];
			while(i<j&&s[i]<pivot)		++i;
			if(i<j)		s[j--]=s[i];
		}
		s[i]=pivot;
		Qsort(s,left,i-1);
		Qsort(s,i+1,right);
	}
}
int main()
{	int F,P,C,M;
	int a,b,c,i;
	int res[MAXN],len;
	while(scanf("%d %d %d %d",&F,&P,&C,&M)!=EOF)
	{	Initial(F);
		while(P--)
		{	scanf("%d %d %d",&a,&b,&c);
			if(c<G[a][b])
				G[a][b]=G[b][a]=c;
		}
		Dijkstra(1);
		len=0;
		for(i=1;i<=C;++i)
		{	scanf("%d",&a);
			if(dis[a]<=M)
				res[len++]=i;
		}
		printf("%d\n",len);
		Qsort(res,0,len-1);
		for(int i=0;i<len;++i)
			printf("%d\n",res[i]);
	}
	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