slack time松弛时间

在这里插入图片描述

#include <stdio.h>
#include <stdlib.h>
typedef struct table
{
    int EC;
    int LC;
}TABLE;
typedef struct table Table;

void initialize(int graph[8][8],int graph1[8][8],int a,int b);

int main()
{

    int graph[8][8];
    int graph1[8][8];
    int i,j;
    int a,b,x;
    Table T[8];
    scanf("%d,%d,%d,",&a,&b,&x);
    for(i=1;i<8;i++)
    {
        T[i].EC=0;
        T[i].LC=100;
    }
    T[1].EC=0;
    initialize(graph,graph1,a,b);
    int temp;
    for(i=1;i<8;i++)
    {
        for(j=1;j<8;j++)
        {
            if(graph[i][j]!=0)
            {
                temp=T[i].EC+graph[i][j];
                if(temp>T[j].EC)
                {
                    T[j].EC=temp;
                }

            }
        }
    }
    for(i=7;i>0;i--)
    {
        for(j=7;j>0;j--)
        {
            if(i==7&&j==7)
            {
                T[i].LC=T[i].EC;
            }
            else
            {
                if(graph1[i][j]!=0)
                {
                    temp=T[i].LC-graph1[i][j];
                    if(temp<T[j].LC)
                    {
                        T[j].LC=temp;
                    }
                }
            }
            
        }
    }
    printf("%d",T[x].LC-T[x].EC);
    /*printf("\n");
    for(i=1;i<8;i++)
    {
        printf("%d,",T[i].LC);
    }
    printf("\n");
    for(i=1;i<8;i++)
    {
        printf("%d,",T[i].EC);
    }*/
    return 0;
}

void initialize(int graph[8][8],int graph1[8][8],int a, int b)
{
    int i,j;
    for(i=0;i<8;i++)
    {
        for(j=0;j<8;j++)
        {
            graph[i][j]=0;
            graph1[i][j]=0;
        }
    }
    graph[1][2]=3;
    graph[1][4]=6;
    graph[1][3]=3;
    graph[2][4]=2;
    graph[3][4]=3;
    graph[3][6]=3;
    graph[4][5]=2;
    graph[4][6]=2;
    graph[4][7]=5;
    graph[5][7]=3;
    graph[6][7]=4;
    graph[2][5]=5;
    graph1[5][2]=5;
    graph1[2][1]=3;
    graph1[4][1]=6;
    graph1[3][1]=3;
    graph1[4][2]=2;
    graph1[4][3]=3;
    graph1[6][3]=3;
    graph1[5][4]=2;
    graph1[6][4]=2;
    graph1[7][4]=5;
    graph1[7][5]=3;
    graph1[7][6]=4;
    graph[a][b]=0;
    graph1[b][a]=0;
}
  • 1
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值