zoukankan      html  css  js  c++  java
  • CF 586B 起点到终点的最短路和次短路之和

    起点是右下角  终点是左上角
    每次数据都是两行的点  输入n 表示有n列
    接下来来的2行是 列与列之间的距离
    最后一行是  行之间的距离
    枚举就行
     
    Sample test(s)
    input
    4
    1 2 3
    3 2 1
    3 2 2 3
    output
    12
    input
    3
    1 2
    3 3
    2 1 3
    output
    11
    input
    2
    1
    1
    1 1
    output
    4

     1 # include <iostream>
     2 # include <cstdio>
     3 # include <cstring>
     4 # include <algorithm>
     5 # include <string>
     6 # include <cmath>
     7 # include <queue>
     8 # define LL long long
     9 using namespace std ;
    10 
    11 const int INF = 0x3f3f3f3f ;
    12 
    13 int a[3][60] ;
    14 int b[60] ;
    15 
    16 int main()
    17 {
    18     int n;
    19     while(scanf("%d",&n) != EOF)
    20     {
    21        int i , j ;
    22        int sum = 0 ;
    23        for (i = 0 ; i < 2  ; i++)
    24           for (j = 0 ; j < n-1 ; j++)
    25            scanf("%d" , &a[i][j]) ;
    26        for (i = 0 ; i < n  ; i++)
    27           scanf("%d" , &b[i]) ;
    28        int ans[3] = {INF , INF , INF} ;
    29        for (i = 0 ; i < n-1  ; i++)
    30        {
    31            sum += a[1][i] ;
    32        }
    33        sum += b[0] ;
    34        ans[2] = sum ;
    35        sort(ans , ans+3) ;
    36        for (i = 0 ; i < n-1  ; i++)
    37        {
    38            sum = sum - a[1][i] + a[0][i] ;
    39            sum = sum - b[i] + b[i+1] ;
    40            ans[2] = sum ;
    41            sort(ans , ans+3) ;
    42        }
    43        printf("%d
    " , ans[0] + ans[1]) ;
    44 
    45 
    46 
    47     }
    48     return 0;
    49 }
    View Code
  • 相关阅读:
    c# Java 静态方法 并发问题
    最效率分页查询
    Hibernate中对象的三种状态
    Spring框架概述
    扫盲Cookies简单理解——关于IE浏览器隐私设置
    实例分析Struts的由来和概述
    操作系统——存储
    Hibernate概述
    操作系统——进程部分
    操作系统——进程死锁
  • 原文地址:https://www.cnblogs.com/mengchunchen/p/4876186.html
Copyright © 2011-2022 走看看