WaltVBAlston @ 2020-02-21 22:25:23
借光(不是这道题)
大家看看我的程序
输入什么都是死循环
全部输入1都是
发现错误的大佬回复或者私信我谢谢
#include<iostream>
#include<iomanip>
using namespace std;
long long x,l,s,k;
long long n,m;
long long w[501][501];
bool flag[501];
long long d[501];
long long disx,disk,diskl;
long long time1;
int main()
{
cin>>x>>l>>s>>k;
cin>>n>>m;
for(long long i=1;i<=n;i++)
{
for(long long j=1;j<=n;j++)
{
w[i][j]=214748367;
}
w[i][i]=0;
d[i]=2147483647;
flag[i]=true;
}
for(long long i=1;i<=m;i++)
{
long long u,v,dis;
cin>>u>>v>>dis;
if(w[u][v]<dis)
{
continue;
}
w[u][v]=dis;
w[v][v]=dis;
}
d[s]=0;
for(long long i=1;i<=n;i++)
{
long long minn=2147483647;
long long index=1;
for(long long j=1;j<=n;j++)
{
if(d[j]<minn&&flag[j]==false)
{
index=j;
minn=d[j];
}
}
flag[index]=true;
for(long long j=1;j<=n;j++)
{
if(d[j]>d[index]+w[index][j])
{
d[j]=d[index]+w[index][j];
}
}
}
disx=d[x];
disk=d[k];
for(long long i=1;i<=n;i++)
{
d[i]=2147483647;
flag[i]=false;
}
d[k]=0;
for(long long i=1;i<=n;i++)
{
long long minn=2147483647;
long long index=1;
for(long long j=1;j<=n;j++)
{
if(d[j]<minn&&flag[j]==false)
{
index=j;
minn=d[j];
}
}
flag[index]=true;
for(long long j=1;j<=n;j++)
{
if(d[j]>d[index]+w[index][j])
{
d[j]=d[index]+w[index][j];
}
}
}
diskl=d[l];
time1=disx-disk;
cout<<fixed<<setprecision(2)<<diskl/time1<<endl;
return 0;
}
by 81179332_ @ 2020-02-21 22:28:21
@Andy_2006 给个数据呗
by WaltVBAlston @ 2020-02-21 22:30:15
数据:
1 5 4 3
1 4 10
2 5 20
2 3 10
3 4 5
输出:6.00
by 81179332_ @ 2020-02-21 22:31:42
@Andy_2006 你这。。。读入写错了
by WaltVBAlston @ 2020-02-21 22:33:51
抱歉写错了
by WaltVBAlston @ 2020-02-21 22:34:08
数据:
1 5 4 3
5 4
1 4 10
2 5 20
2 3 10
3 4 5
输出:6.00
by 81179332_ @ 2020-02-21 22:37:38
不是死循环
by 81179332_ @ 2020-02-21 22:38:12
@Andy_2006 你最后time1等于0 RE了
by WaltVBAlston @ 2020-02-21 22:40:58
oh
by WaltVBAlston @ 2020-02-21 22:41:11
谢谢我看看
by WaltVBAlston @ 2020-02-21 22:42:54
不会吧
time1不会是零啊