• 华东交通大学2018年ACM“双基”程序设计竞赛 K


    MIKU酱是个玩游戏氪金的人,游戏公司给她制定了新的规则,如果想从关卡i到关卡j,你需要交一些钱就可以了,但同时,MIKU酱的爸爸zjw很爱她,所以她可以每过一关就向她爸要一次钱,但她爸每次给他的钱是固定的,MIKU酱是个不会节省的女孩,哪怕每次多出来的钱,她也会拿去买肥宅快乐水,所以每次要的钱一定花完,因为MIKU酱不想挨骂,所以希望每次他爸给她的钱最少。
    tips(到达第n关即通过,每到达一关一定能通过这关)

    输入描述:

    多组输入,每个样例第一行输入两个整数n,m(2<=n<=200,1<=m<=1000)表示关卡和规则的数量,接下来m行规则,每行输入x,y,w(w<=1000),表示从关卡x到y需要缴纳w的费用,保证题目有解,不会出现x=y的情况

    输出描述:

    输出一行,代表最少的钱
    示例1

    输入

    复制
    4 4
    1 2 2
    1 3 1
    2 4 3
    3 4 1

    输出

    复制
    1


     1 #include <cstdio>
     2 #include <cstring>
     3 #include <iostream>
     4 #include <algorithm>
     5 #include <vector>
     6 #include <queue>
     7 #include <set>
     8 #include <map>
     9 #include <string>
    10 #include <cmath>
    11 #include <cstdlib>
    12 #include <ctime>
    13 using namespace std;
    14 #define  ll long long 
    15 #define  P pair<int,int>
    16 #define  ph   push_back
    17 const int inf=0x3f3f3f3f;
    18 int n,m,x,y,w;
    19 const int N =220;
    20 int dis[N];
    21 vector<P>ve[N];
    22 void  init(){
    23     for(int i=0;i<N;i++) {
    24         dis[i]=inf;
    25         ve[i].clear();
    26     }
    27 }
    28 int  bfs(int sta){
    29     priority_queue<P,vector<P>,greater<P> >q;
    30     dis[sta] =0;
    31     q.push(P(0,sta));
    32     while(!q.empty()){
    33         P p =q.top();
    34         q.pop();
    35         int fi =p.first,se=p.second;//fi:最短路径上到se位置的题目答案
    36         if(se==n) return  fi;
    37         for(int i=0;i<ve[se].size();i++){
    38             P pp=ve[se][i];
    39             int ff=pp.first,ss=pp.second;
    40             if(dis[ff]>max(ss,fi)){
    41                 dis[ff]=max(ss,fi);//变小了
    42                 q.push(P(dis[ff],ff));
    43             }            
    44         }
    45     }
    46     return  inf;
    47 }
    48 int  main()
    49 {
    50     while(~scanf("%d%d",&n,&m)){
    51         init();
    52         for(int  i=0;i<m;i++){
    53             scanf("%d%d%d",&x,&y,&w);
    54             ve[x].ph(P(y,w));
    55         }
    56         int xx = bfs(1);
    57         printf("%d
    ",xx);
    58     }
    59     return 0;
    60 }
  • 相关阅读:
    python smtplib email
    python merry -- error handling in the real world
    python os.path
    python logging
    Python演讲笔记1
    python DBUtils.PooledDB 中 maxcached 和 maxconnections
    Effective Python2 读书笔记3
    Effective Python2 读书笔记2
    MVC验证session是否过期,在每个action执行之前验证
    int类型的正负数转换
  • 原文地址:https://www.cnblogs.com/tingtin/p/9975347.html
Copyright © 2020-2023  润新知