比赛 10101115 评测结果 WWWWWWWWWW
题目名称 最小密度路径 最终得分 0
用户昵称 wangwangdog 运行时间 0.000 s
代码语言 C++ 内存使用 0.00 MiB
提交时间 2010-11-15 11:17:11
显示代码纯文本
#include<stdio.h>
long long n,m,map[51][51],i,j,k,nn,a,b,l;
struct aaa
{
	long long l,bian;
}d[51][51];
FILE *fin,*fout;
int main()
{
	fin=fopen("path.in","rb");
	fout=fopen("path.out","wb");
	fscanf(fin,"%lld%lld\n",&n,&m);
	for(i=1;i<=n;i++)
		for(j=1;j<=n;j++)
			map[i][j]=-1;
	for(i=1;i<=m;i++)
	{
		fscanf(fin,"%lld%lld%lld\n",&a,&b,&l);
		map[a][b]=l;
	}
	for(i=1;i<=n;i++)
		for(j=1;j<=n;j++)
		{
			d[i][j].l=map[i][j];
			if(map[i][j]!=-1)d[i][j].bian=1;
			else d[i][j].bian=0;
		}
	for(k=1;k<=n;k++)
		for(i=1;i<=n;i++)
			for(j=1;j<=n;j++)
			{
				if(d[i][k].l!=-1&&d[k][j].l!=-1&&d[i][j].l!=-1)
				{
					if((d[i][k].l+d[k][j].l)/(d[i][k].bian+d[k][j].bian)<=d[i][j].l/d[i][j].bian)
						{d[i][j].l=d[i][k].l+d[k][j].l;d[i][j].bian=d[i][k].bian+d[k][j].bian;}
				}
				if(d[i][k].l!=-1&&d[k][j].l!=-1&&d[i][j].l==-1)
				{
					d[i][j].l=d[i][k].l+d[k][j].l;
					d[i][j].bian=d[i][k].bian+d[k][j].bian;
				}
				
			}
	fscanf(fin,"%lld\n",&nn);
	for(i=1;i<=nn;i++)
	{
		fscanf(fin,"%lld%lld\n",&a,&b);
		if(d[a][b].l!=-1)
		{
		double y=d[a][b].l;
		double x=y/d[a][b].bian;
		fprintf(fout,"%0.3lf\n",x);
		}
		else fprintf(fout,"OMG!");
	}
	fclose(fin);
	fclose(fout);
	return 0;
}