POJ 1797Heavy Transportation +第七届河南省程序设计大赛NYOJ1248 海岛争霸 (最小生成树变形/djs变形)

本文介绍了一种用于解决最大最小路径问题的算法,该算法能够找到两个节点间路径上的最大权重的最小值,适用于如重型运输规划等场景。文章提供了两个具体的实现案例,包括寻找最大允许重量的路径和最小危险程度的航海路线。
Heavy Transportation
Time Limit: 3000MS Memory Limit: 30000K
Total Submissions: 33898 Accepted: 8968

Description

Background 
Hugo Heavy is happy. After the breakdown of the Cargolifter project he can now expand business. But he needs a clever man who tells him whether there really is a way from the place his customer has build his giant steel crane to the place where it is needed on which all streets can carry the weight. 
Fortunately he already has a plan of the city with all streets and bridges and all the allowed weights.Unfortunately he has no idea how to find the the maximum weight capacity in order to tell his customer how heavy the crane may become. But you surely know. 

Problem 
You are given the plan of the city, described by the streets (with weight limits) between the crossings, which are numbered from 1 to n. Your task is to find the maximum weight that can be transported from crossing 1 (Hugo's place) to crossing n (the customer's place). You may assume that there is at least one path. All streets can be travelled in both directions.

Input

The first line contains the number of scenarios (city plans). For each city the number n of street crossings (1 <= n <= 1000) and number m of streets are given on the first line. The following m lines contain triples of integers specifying start and end crossing of the street and the maximum allowed weight, which is positive and not larger than 1000000. There will be at most one street between each pair of crossings.

Output

The output for every scenario begins with a line containing "Scenario #i:", where i is the number of the scenario starting at 1. Then print a single line containing the maximum allowed weight that Hugo can transport to the customer. Terminate the output for the scenario with a blank line.

Sample Input

1
3 3
1 2 3
1 3 4
2 3 5

Sample Output

Scenario #1:
4

题意:n个城市,m条街道,城市x-城市y的道路承重w  求城市1-城市n的最大承重 
样例:1-3 承重4 ,1-2-3 最大称重为min(3,5)=3 所以最大称重为4
求1~n中所有联通路上的最小边的最大值,最小生成树变形(也可最短路变形)

code:
#include<stdio.h>
#include<string.h>
#include<algorithm>
#include<iostream>
using namespace std;
const int N=1005;
#define inf 0x3f3f3f3f
int n,m;
int mp[N][N],vis[N],dis[N];
int prim()
{
    int pos=1;
    vis[pos]=1;
    for(int i=1;i<=n;i++)
    {
        dis[i]=mp[pos][i];
    }
    for(int i=1;i<n;i++)
    {
        int maxx=-1;
        for(int j=1;j<=n;j++)
        {
            if(!vis[j]&&dis[j]>maxx)
            {
                maxx=dis[j];
                pos=j;
            }
        }
        vis[pos]=1;
        for(int j=1;j<=n;j++)
        {
            if(!vis[i])
            dis[j]=max(dis[j],min(dis[pos],mp[pos][j]));
        }
    }
    return dis[n];
}
int main()
{
    int T,t=0;
    scanf("%d",&T);
    while(T--)
    {

        scanf("%d%d",&n,&m);
        memset(mp,0,sizeof(mp));//与最小生成树的初始值不同
        memset(vis,0,sizeof(vis));
       while(m--)
       {
           int x,y,z;
           scanf("%d%d%d",&x,&y,&z);
           if(mp[x][y]<z)
            mp[x][y]=mp[y][x]=z;
       }
       int ans=prim();
       printf("Scenario #%d:\n%d\n\n",++t,ans);
    }
}







NYOJ1248 海岛争霸

海岛争霸

时间限制:1000 ms  |  内存限制:65535 KB
难度:3
描述
神秘的海洋,惊险的探险之路,打捞海底宝藏,激烈的海战,海盗劫富等等。加勒比海盗,你知道吧?杰克船长驾驶着自己的的战船黑珍珠1号要征服各个海岛的海盜,最后成为海盗王。 这是一个由海洋、岛屿和海盗组成的危险世界。杰克船长准备从自己所占领的岛屿A开始征程,逐个去占领每一个岛屿。面对危险重重的海洋与诡谲的对手,如何凭借智慧与运气,建立起一个强大的海盗帝国。
杰克船长手头有一张整个海域的海图,上面详细地记录了各个海屿的位置,以及海屿之间的通航路线。但他发现,有的航海路线太危险了,杰克船长的战船很难直接通过,他必须想方设法绕道航行;还有的岛屿根本到达不了。
杰克船长现在想把航行的危险程度降到最小。具体地来说,就是杰克船长提出若干个询问,他想知道从岛屿A 到岛屿B 有没有行驶航线,若有的话,所经过的航线,危险程度最小可能是多少。
输入
第1行: N M 表示有N个岛屿,M条直航路线 第2~M+1行: A B V 表示从岛屿A到岛屿B的航海路线的危险程度值为V。 接下面一行 : Q 表示询问的次数。 之后有Q个行: A B 表示询问从岛屿A 到岛屿B 所经过的航线,危险程度最小值 1<N≤100 0<M≤500 1≤ Q≤20 0 < V≤1000, 所有数据都是正整数。输入数据之间有一个空格。
输出
对于每个询问,输出占一行,一个整数,表示从岛屿A 到岛屿B 所经过的航线,危险程度最小值;若从岛屿A 无法到达岛屿B,则输出-1。
样例输入
10 8
1 2 5
1 3 2
2 3 11
2 4 6
2 4 4
6 7 10
6 10 5
10 7 2
5
2 3
1 4
3 7
6 7
8 3
样例输出
5
5
-1
5
-1

求连通路上最大边的最小值  和上面那个题正好相反,改下mp的初始化  dis[j]=min(dis[j],max(dis[pos],mp[pos][j]))
CODE:
#include<stdio.h>
#include<string.h>
#include<vector>
#include<queue>
#include<algorithm>
using namespace std;
const int N=105;
#define inf 0x3f3f3f3f
bool vis[N];
int n;
int dis[N],mp[N][N];
void djs(int s,int t)
{
    memset(vis,0,sizeof(vis));
    int pos=s;
    vis[pos]=true;
    for(int i=1; i<=n; i++)
    {
        dis[i]=mp[pos][i];
    }
    for(int j=1; j<=n; j++)
    {
        int minn=inf;
        for(int i=1; i<=n; i++)
        {
            if(!vis[i]&&dis[i]<minn)
            {
                minn=dis[i];
                pos=i;
            }
        }
        vis[pos]=true;
        for(int i=1; i<=n; i++)
        {
            if(!vis[i])
            dis[i]=min(dis[i],max(dis[pos],mp[pos][i]));
        }
    }
    if(dis[t]==inf) printf("-1\n");
    else printf("%d\n",dis[t]);
}
int main()
{
    int m,x,y,z,Q;
    scanf("%d%d",&n,&m);
    for(int i=1; i<=n; i++)
    {
        for(int j=1; j<=n; j++)
        {
            mp[i][j]=inf;
        }
    }
    while(m--)
    {
        scanf("%d%d%d",&x,&y,&z);
        if(mp[x][y]>z)
           mp[x][y]=mp[y][x]=z;
    }
    scanf("%d",&Q);
    while(Q--)
    {
        scanf("%d%d",&x,&y);
        djs(x,y);
    }
}


求最大生成树可以将权值变成负的,求下最小生成树,结果取绝对值
内容概要:本文研究了一种基于改进ICEEMDAN的火电-蓄电池-飞轮混合储能联合调频协同控制策略,旨在提升电力系统频率调节的快速响应能力与运行稳定性。通过引入改进的自适应噪声完备集合经验模态分解(ICEEMDAN)方法,对电网频率偏差信号进行多时间尺度分解,精确分离高频与低频动态分量,并据此实现功率的差异化分配:高频成分由响应迅速的飞轮储能承担,低频成分由能量密度高的蓄电池处理,同时结合火电机组的基础调频能力,构建火电-混合储能多源协同控制架构。该策略充分发挥各类储能技术的优势,有效缓解单一储能系统的压力,延长设备寿命,并提升系统整体调频性能。文中提供了完整的Matlab仿真代码实现,验证了该方法在抑制频率波动、优化储能出力、提高系统可靠性和经济性方面的显著效果。; 适合人群:具备电力系统分析、自动控制理论及新能源技术等相关专业知识背景,熟悉Matlab/Simulink仿真平台,从事电力系统调频控制、混合储能系统优化、多时间尺度能量管理等领域研究的研究生、科研人员及工程技术人员。; 使用场景及目标:①深入研究混合储能系统在电网一次调频与二次调频中的功率分配机制与协调控制逻辑;②掌握ICEEMDAN信号分解技术在能源系统动态特征提取与多尺度控制中的应用方法;③实现火电机组与多类型储能协同参与调频的仿真建模、算法开发与性能对比分析;④为综合能源系统、微电网及新型电力系统的多源多时间尺度协调控制提供理论依据与技术参考。; 阅读建议:建议结合提供的Matlab代码逐模块分析算法实现流程,重点理解信号分解、模态分量判别、功率分配规则及控制器设计等关键环节,可通过调整系统参数、模拟不同扰动工况进行仿真测试,进一步开展灵敏度分析与策略优化,以深化对协同控制机理的认识并拓展其实际应用价值。
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值