数据结构第八次作业第三题(Slack time)

C. Slack Time
运行时间限制: 1000 运行内存限制: 65536
作者: scsxuke 是否specialjudge: False
题目描述
Given an Acyclic Graph as the figure (shared by QQ), delete one edge of activity, then calculate the slack time of the left nodes.
Output the slack time of a specified node

input
1 line of numbers seperated by commar, the first two are the nodes numbers of the edge to be deleted, the third gives the node number to be output the slack time

output
the slack time of the specified node

输入样例
2,5,5,
输出样例
1
在这里插入图片描述

#include <stdio.h>

typedef struct graph
{
    int weight[7][7];
    int LastC[7];
    int EarlyC[7];
} Graph;

int findmax(Graph g, int index)
{
    int max = 0;
    for (int i = 0; i < 7; i++)
    {
        if (g.weight[i][index] != 0)
        {
            if (g.EarlyC[i] + g.weight[i][index] > max)
                max = g.EarlyC[i] + g.weight[i][index];
        }
    }
    return max;
}

int findmin(Graph g, int index)
{
    int min = 99999;
    for (int i = 0; i < 7; i++)
    {
        if (g.weight[index][i] != 0)
        {
            if (g.LastC[i] - g.weight[index][i] < min)
                min = g.LastC[i] - g.weight[index][i];
        }
    }
    return min;
}

int main()
{
    Graph g;
    int n1, n2, need;
    scanf("%d,%d,%d", &n1, &n2, &need);
    for (int i = 0; i < 7; i++)
    {
        for (int j = 0; j < 7; j++)
        {
            g.weight[i][j] = 0;
        }
        g.LastC[i] = g.EarlyC[i] = 0;
    }
    g.weight[0][1] = 3;
    g.weight[0][2] = 3;
    g.weight[0][3] = 6;
    g.weight[1][3] = 2;
    g.weight[1][4] = 5;
    g.weight[2][3] = 3;
    g.weight[2][5] = 3;
    g.weight[3][4] = 2;
    g.weight[3][5] = 2;
    g.weight[3][6] = 5;
    g.weight[4][6] = 3;
    g.weight[5][6] = 4;

    g.weight[n1 - 1][n2 - 1] = 0;
    g.EarlyC[0] = 0;
    for (int i = 0; i < 7; i++)
    {
        int ret = findmax(g, i);
        g.EarlyC[i] = ret;
    }
    g.LastC[6] = g.EarlyC[6];
    for (int i = 7 - 2; i >= 0; i--)
    {
        int ret = findmin(g, i);
        g.LastC[i] = ret;
    }
    printf("%d", g.LastC[need - 1] - g.EarlyC[need - 1]);
    return 0;
}
  • 1
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值