POJ3268 求最长路径(一来一回)

探讨了在一个由N个农场组成的网络中,每个农场的一头牛如何找到参加聚会并返回的最短路径,利用图论和最短路径算法解决实际问题。
Silver Cow Party
Time Limit: 2000MS Memory Limit: 65536K
Total Submissions: 16180 Accepted: 7393

Description

One cow from each of N farms (1 ≤ N ≤ 1000) conveniently numbered 1..N is going to attend the big cow party to be held at farm #X (1 ≤ X ≤ N). A total of M (1 ≤ M ≤ 100,000) unidirectional (one-way roads connects pairs of farms; road i requires Ti (1 ≤ Ti ≤ 100) units of time to traverse.

Each cow must walk to the party and, when the party is over, return to her farm. Each cow is lazy and thus picks an optimal route with the shortest time. A cow's return route might be different from her original route to the party since roads are one-way.

Of all the cows, what is the longest amount of time a cow must spend walking to the party and back?

Input

Line 1: Three space-separated integers, respectively:  NM, and  X 
Lines 2.. M+1: Line  i+1 describes road  i with three space-separated integers:  AiBi, and  Ti. The described road runs from farm  Ai to farm  Bi, requiring  Ti time units to traverse.

Output

Line 1: One integer: the maximum of time any one cow must walk.

Sample Input

4 8 2
1 2 4
1 3 2
1 4 7
2 1 1
2 3 5
3 1 2
3 4 4
4 2 3

Sample Output

10

Hint

Cow 4 proceeds directly to the party (3 units) and returns via farms 1 and 3 (7 units), for a total of 10 time units.

Source

USACO 2007 February Silver

#include<stdio.h>
#include<string.h>
#define inf 0xffffff
int mp[1020][1020];
int visit[1020];
int dis[1020];
int disb[1020];
int n,m,x;
void suan()
{
    int i,j,k;
    int mincost;


    memset(visit,0,sizeof(visit));//v函数判断有没有访问过。。。其实自己也不太懂QAQ
    for(int i=1; i<=n; i++)//cost[i]函数表示1到i的最短距离
    {
        dis[i]=mp[x][i];
        disb[i]=mp[i][x];
    }
    for(i=1; i<=n; i++)//不断更新吧。QAQ
    {
        mincost=inf;
        for(j=1; j<=n; j++)//先找出一个1到k(j)的最短距离
        {
            if(!visit[j]&&mincost>dis[j])
            {
                mincost=dis[j];
                k=j;
            }
        }

        visit[k]=1;
        for(j=1; j<=n; j++)//对于新的j,如果刚才的最短路(1到k)+k到j的距离比直接从1到j要段,那么1到j的最短距离就更新为1到k再到j的距离
        {
            if(!visit[j]&&dis[j]>dis[k]+mp[k][j])
            {
                dis[j]=dis[k]+mp[k][j];
            }
        }

    }
    memset(visit,0,sizeof(visit));//其实不明白这个大循环是什么意思QAQ。。。。。。。。。
    for(i=1; i<=n; i++)//不断更新吧。QAQ
    {
        mincost=inf;
        for(j=1; j<=n; j++)//先找出一个1到k(j)的最短距离
        {
            if(!visit[j]&&mincost>disb[j])
            {
                mincost=disb[j];
                k=j;
            }
        }

        visit[k]=1;
        for(j=1; j<=n; j++)//对于新的j,如果刚才的最短路(1到k)+k到j的距离比直接从1到j要段,那么1到j的最短距离就更新为1到k再到j的距离
        {
            if(!visit[j]&&disb[j]>disb[k]+mp[j][k])
            {
                disb[j]=disb[k]+mp[j][k];
            }
        }

    }
   mincost=-1;
    for(i=1; i<=n; i++)
    {
        if(dis[i]+disb[i]>mincost)
            mincost=dis[i]+disb[i];
    }
    printf("%d\n",mincost);
}
int main()
{
    while(scanf("%d%d%d",&n,&m,&x)!=EOF)
    {
        memset(visit,0,sizeof(visit));
        for(int  i=1; i<=n; i++)
            for(int j=1; j<=n; j++)
            {
                if(i==j)
                    mp[i][j]=0;
                else mp[i][j]=inf;
            }
        while(m--)
        {
            int a,b,c;
            scanf("%d%d%d",&a,&b,&c);
            mp[a][b]=c;
        }
        suan();

    }
}



【电力系统】单机无穷大电力系统短路故障暂态稳定Simulink仿真(带说明文档)内容概要:本文档围绕“单机无穷大电力系统短路故障暂态稳定Simulink仿真”展开,提供了完整的仿真模型与说明文档,重点研究电力系统在发生短路故障后的暂态稳定性问题。通过Simulink搭建单机无穷大系统模型,模拟不同类型的短路故障(如三相短路),分析系统在故障期间及切除后的动态响应,包括发电机转子角度、转速、电压和功率等关键参数的变化,进而评估系统的暂态稳定能力。该仿真有助于理解电力系统稳定性机理,掌握暂态过程分析方法。; 适合人群:电气工程及相关专业的本科生、研究生,以及从事电力系统分析、运行与控制工作的科研人员和工程师。; 使用场景及目标:①学习电力系统暂态稳定的基本概念与分析方法;②掌握利用Simulink进行电力系统建模与仿真的技能;③研究短路故障对系统稳定性的影响及提高稳定性的措施(如故障清除时间优化);④辅助课程设计、毕业设计或科研项目中的系统仿真验证。; 阅读建议:建议结合电力系统稳定性理论知识进行学习,先理解仿真模型各模块的功能与参数设置,再运行仿真并仔细分析输出结果,尝试改变故障类型或系统参数以观察其对稳定性的影响,从而深化对暂态稳定问题的理解。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值