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
  • 相关阅读:
    树分治 poj 1741
    堆 poj 2010
    堆 poj 2442
    堆的基本操作
    状态压缩codeforces 11 D
    状态压缩 CSU1129 送货到家
    炮兵阵地 POJ 1185
    状态压缩 HDU4539 郑厂长系列故事——排兵布阵
    状态压缩 HDU 3182
    android手势创建及识别
  • 原文地址:https://www.cnblogs.com/baby-mouse/p/4445135.html
Copyright © 2011-2022 走看看