Floyd挂了求助

P1001 A+B Problem

luqyou @ 2022-10-17 17:01:08

#include<bits/stdc++.h>
using namespace std;
int a,b,f[11][11],n=3;
int main(){
    memset(f,0x3f,sizeof(f));
    scanf("%d%d",&a,&b); 
    f[1][2]=a;
    f[1][1]=0;
    f[2][1]=a;
    f[2][2]=0;
    f[3][2]=b;
    f[2][3]=b;
    f[3][3]=0;
    for(int k=1;k<=n;k++){
        for(int i=1;i<=n;i++){
            for(int j=1;j<=n;j++){
                f[i][j]=min(f[i][j],f[i][k]+f[k][j]);
            }
        }
    }
    printf("%d",f[1][3]);
    return 0; 
}

by AKPC @ 2023-02-18 13:38:53

#include <bits/stdc++.h>
using namespace std;
#define int long long
int a,b,n=3,f[5][5];
signed main(){
    cin>>a>>b;
    for (int i=1;i<=n;i++) for (int j=1;j<=n;j++) f[i][j]=1145141919810;
    f[1][2]=a,f[2][3]=b;
    for (int x=1;x<=n;x++)
        for (int i=1;i<=n;i++)
            for (int j=1;j<=n;j++)
                if (i!=j) f[i][j]=min(f[i][j],f[i][x]+f[x][j]);
    cout<<f[1][3];
    return 0;
}

蒟蒻的 floyd


上一页 |