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

Re:高手看看我程序有啥问题,为什么总wa阿,不就是求最短路问题吗?

Posted by hotrhino at 2008-04-10 11:43:30 on Problem 2394
In Reply To:Re:高手看看我程序有啥问题,为什么总wa阿,不就是求最短路问题吗? Posted by:flymouse at 2008-04-10 03:47:25
用了多case也不行阿,把原来for (k=1; k<=f; k++)	ver[k][k]=MAX;的地方去了也不行,明明是简单的最短路问题,看数据的规模可以用floyd就用了floyd,图好写代码,但总wa,真打击人的,飞鼠大侠,我高中时到过你的空间学东西,现在你那个oi空间貌似找不到,能不能发你新空间的地址给我(hotrhino@163.com),题很简单,你还没做这题呢,应该半个小时不到就可以做出来了,帮帮我看看有什么问题好吗?

#include<stdio.h>
int main(){
	int ver[505][505];
	int MAX=1000000;
	int f,p,cow,timeS;
	while(scanf("%d%d%d%d",&f,&p,&cow,&timeS)!=EOF){
		int i,j,k;
		for (i=0; i<=f; i++)
			for (j=0; j<=f;j++)
				ver[i][j]=MAX;
		int tmp;
		for (k=0; k<p; k++){
				scanf("%d%d",&i,&j);
				scanf("%d",&tmp);
				if (tmp<ver[i][j]){
					ver[j][i]=tmp;
					ver[i][j]=tmp;
				}
		};
		for (k=1; k<=f;k++)
			for (i=1;i<=f; i++)
				for (j=1;j<=f; j++)
					if (ver[i][k]+ver[k][j]<ver[i][j])
						ver[i][j]=ver[i][k]+ver[k][j];
		int cowstr[500];
		int count=0;
		for (i=1; i<=cow; i++){
			scanf("%d",&cowstr[i]);
			if (ver[cowstr[i]][1]<=timeS)
				count++;
		}
		printf("%d\n",count);
		for (i=1; i<=cow; i++)
			if (ver[cowstr[i]][1]<=timeS)
				printf("%d\n",i);
	}
	return 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