zoukankan      html  css  js  c++  java
  • uvalive5818 uva12376 As Long as I Learn, I Live

    题意:给出一个又向图每个图有权值和编号(正方形里的是编号),从第0号节点开始每次向当前节点所连的点中权值最大的节点移动(不会存在权值相同的节点),问最后所在的节点编号和经过的节点的权值之和。

    解:模拟就好~

     1 #include<cstdio>
     2 #include<algorithm>
     3 #include<cmath>
     4 #include<cstring>
     5 #include<vector>
     6 
     7 using namespace std;
     8 
     9 int T;
    10 int n,m;
    11 int f[107];
    12 vector <int> G[107];
    13 
    14 int main(){
    15     scanf("%d",&T);
    16     for (int cas=1;cas<=T;cas++){
    17             scanf("%d%d",&n,&m);
    18             for (int i=0;i<n;i++){
    19                     scanf("%d",&f[i]);
    20                     G[i].clear();
    21             }
    22             for (int i=0;i<m;i++){
    23                     int x,y;
    24                     scanf("%d%d",&x,&y);
    25                     G[x].push_back(y);
    26             }
    27             int now=0;
    28             int totv=0;
    29             while (1){
    30             //        printf("%d %d
    ",now,totv);
    31                     int to=0;
    32                     int tov=0;
    33                     for (int i=0;i<G[now].size();i++){
    34                             if (f[G[now][i]]>tov){
    35                                     to=G[now][i];
    36                                     tov=f[G[now][i]];
    37                             }
    38                     }
    39                     if (to==0) break;
    40                     totv+=tov;
    41                     now=to;
    42             }
    43             printf("Case %d: %d %d
    ",cas,totv,now);
    44     }
    45     return 0;
    46 }
    47 /*
    48 2
    49 6 6
    50 0 8 9 2 7 5
    51 5 4
    52 5 3
    53 1 5
    54 0 1
    55 0 2
    56 2 1
    57 6 6
    58 0 8 9 2 6 5
    59 5 4
    60 5 3
    61 1 5
    62 0 1
    63 0 2
    64 2 1
    65 */
    View Code
  • 相关阅读:
    用Creator实现一个擀面的效果
    游戏开发中的多语言处理
    Docker(六)容器数据卷
    Docker(五)Docker镜像讲解
    Docker(四)Docker镜像安装
    Docker(三)Docker常用命令
    Docker(二)Docker配置
    nginx 与 tomcat 组合搭建web服务
    Zookeeper 使用
    tomcat-manager 设置
  • 原文地址:https://www.cnblogs.com/baby-mouse/p/4445135.html
Copyright © 2011-2022 走看看