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 WaltVBAlston @ 2020-02-21 22:43:23
你大概能看出来这道题想表达什么吧
by WaltVBAlston @ 2020-02-21 22:43:43
不方便展开题面
by 81179332_ @ 2020-02-21 22:44:18
@Andy_2006 你把disx和disk输出来会发现它们都是无穷
by XQLG @ 2020-02-21 22:47:22
虽然我看不懂
但是我认为
这里```cpp
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;
}
第五行少了一个4
by 81179332_ @ 2020-02-21 22:53:37
@Andy_2006 改完了,两个地方有问题
#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]=2147483647;
}
w[i][i]=0;
d[i]=2147483647;
}
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][u]=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:53:52
另外你的输出方式我看不懂
by WaltVBAlston @ 2020-02-21 22:54:01
多谢
有个地方定义错了
多谢多谢
by WaltVBAlston @ 2020-02-21 22:57:01
@81179332_
%%%
您有兴趣来我的出题组吗
by ༺ʚFLYɞ༻ @ 2020-02-21 23:18:32
@Andy_2006
这代码......