D - Destination Unknown Gym - 100625D -最短路

  • D - Destination Unknown

  •  Gym - 100625D 
  • 题意:n个点m条边,s为起点,给一些终点,每一步只能走最短路问有哪些从起点到终点的最短路经过g,h
  • 思路:跑一边起点s的最短路,再分别跑一边以g,h为起点的最短路,然后判断是否存在从s-t[i]经过g,h的最短路
  • 不能记录路径来判断是因为可能有多条最短路会把g,h覆盖。
  • #include<bits/stdc++.h>
    using namespace std;
    #define inf 0x3f3f3f3f
    #define maxn 52005
    bool vis[maxn];
    int n,m,t,s,g,head[maxn],pre[maxn],px,minn;
    int a,b,d,x[maxn],cnt,h,T,dis[5][maxn];
    vector<int>ans;
    struct node
    {
        int v,to,d;
    } edge[maxn*2];
    void add(int x,int y,int z)
    {
        edge[++cnt].v=y;
        edge[cnt].d=z;
        edge[cnt].to=head[x];
        head[x]=cnt;
    }
    struct edg
    {
        int ord,w;
        bool operator<(const edg&b)const
        {
            return w>b.w;
        }
    } top;
    void dij(int s,int ord)
    {
        priority_queue<edg>q;
        q.push(edg{s,0});
        dis[ord][s]=0;
        while(!q.empty())
        {
            top=q.top();
            q.pop();
            for(int i=head[top.ord]; i!=-1; i=edge[i].to)
            {
                int v=edge[i].v;
                int w=edge[i].d;
                if(dis[ord][v]>dis[ord][top.ord]+w)
                {
                    dis[ord][v]=dis[ord][top.ord]+w;
                    q.push(edg{v,dis[ord][v]});
                }
            }
        }
    }
    int main()
    {
        scanf("%d",&T);
        while(T--)
        {
            cnt=0;
            ans.clear();
            memset(dis,inf,sizeof(dis));
            memset(head,-1,sizeof(head));
            scanf("%d%d%d",&n,&m,&t);
            scanf("%d%d%d",&s,&g,&h);
            while(m--)
            {
                scanf("%d%d%d",&a,&b,&d);
                add(a,b,d);
                add(b,a,d);
            }
            dij(s,1);
            dij(h,3);
            dij(g,2);
            minn=dis[2][h];
            for(int i=0; i<t; i++)
            {
                scanf("%d",&x[i]);
                if(dis[1][x[i]]==dis[2][x[i]]+dis[1][h]+minn)
                    ans.push_back(x[i]);
                else if(dis[1][x[i]]==dis[3][x[i]]+dis[1][g]+minn)
                    ans.push_back(x[i]);
            }
            sort(ans.begin(),ans.end());
            int len=ans.size();
            for(int i=0; i<len; i++)
                if(i==len-1)printf("%d\n",ans[i]);
                else printf("%d ",ans[i]);
        }
        return 0;
    }
    

     

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
The “INVERTED PENDULUM, ANALYSIS, DESIGN AND IMPLEMENTATION” is a collection of MATLAB functions and scripts, and SIMULINK models, useful for analyzing Inverted Pendulum System and designing Control System for it. This report & MATLAB-files collection are developed as a part of practical assignment on Control System Analysis, Design & Development practical problem. The assigned problem of INVERTED PENDULUM is a part of Lab Work of Control System – III Course at the INSTITUTE OF INDUSTRIAL ELECTRONICS ENGINEERING (IIEE), KARACHI, PAKISTAN. The Inverted Pendulum is one of the most important classical problems of Control Engineering. Broom Balancing (Inverted Pendulum on a cart) is a well known example of nonlinear, unstable control problem. This problem becomes further complicated when a flexible broom, in place of a rigid broom, is employed. Degree of complexity and difficulty in its control increases with its flexibility. This problem has been a research interest of control engineers. Control of Inverted Pendulum is a Control Engineering project based on the FLIGHT SIMULATION OF ROCKET OR MISSILE DURING THE INITIAL STAGES OF FLIGHT. The AIM OF THIS STUDY is to stabilize the Inverted Pendulum such that the position of the carriage on the track is controlled quickly and accurately so that the pendulum is always erected in its inverted position during such movements. This practical exercise is a presentation of the analysis and practical implementation of the results of the solutions presented in the papers, “Robust Controller for Nonlinear & Unstable System: Inverted Pendulum” [3] and “Flexible Broom Balancing” [4], in which this complex problem was analyzed and a simple yet effective solution was presented. The details of these papers can be looked in the BIBLIOGRAPHY section.
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值