zoukankan      html  css  js  c++  java
  • 『题解』Codeforces656E Out of Controls

    更好的阅读体验

    Portal

    Portal1: Codeforces

    Portal2: Luogu

    Description

    You are given a complete undirected graph. For each pair of vertices you are given the length of the edge that connects them. Find the shortest paths between each pair of vertices in the graph and return the length of the longest of them.

    Input

    The first line of the input contains a single integer (N (3 le N le 10)).

    The following (N) lines each contain (N) space-separated integers. jth integer in ith line aij is the length of the edge that connects vertices (i) and (j). (a_{ij} = a_{ji}, a_{ii} = 0, 1 le a_{ij} le 100) for (i e j).

    Output

    Output the maximum length of the shortest path between any pair of vertices in the graph.

    Sample Input1

    3
    0 1 1
    1 0 4
    1 4 0
    

    Sample Output1

    2
    

    Sample Input2

    4
    0 1 2 3
    1 0 4 5
    2 4 0 6
    3 5 6 0
    

    Sample Output2

    5
    

    Hint

    You're running short of keywords, so you can't use some of them:

    define
    do
    for
    foreach
    while
    repeat
    until
    if
    then
    else
    elif
    elsif
    elseif
    case
    switch
    

    Solution

    这题的(n)最大只有(10),求的是两点见的最大的最短路,我们直接用Floyd解决。

    但这是一道愚人节的题,题目规定我们不能使用一些语法,我们直接可以用这样的形式解决:

    #defin
    e ... ...
    

    注意,把for改为大写还是会判错。

    Code

    #include<iostream>
    #include<algorithm>
    #include<cstdio>
    #include<cstring>
    #include<cmath>
    #defin
    e rep fo
    r
    
    using namespace std;
    
    const int INF = 0x3f3f3f3f, MAXN = 15;
    int n, map[MAXN][MAXN];
    int main() {
        scanf("%d", &n);
        rep (int i = 1; i <= n; i++)
            rep (int j = 1; j <= n; j++)
                scanf("%d", &map[i][j]);
        rep (int k = 1; k <= n; k++)
            rep (int i = 1; i <= n; i++)
                rep (int j = 1; j <= n; j++)
                    map[i][j] = min(map[i][j], map[i][k] + map[k][j]);//Floyd
        int ans = -INF;
        rep (int i = 1; i <= n; i++)
            rep (int j = 1; j <= n; j++)
                ans = max(ans, map[i][j]);
        printf("%d
    ", ans);
    }
    
  • 相关阅读:
    计算机网络 3.* 数据通信技术基础 .1
    计算机网络3.2&3.3(第二节介质&第三节多路复用)
    python mooc 3维可视化<第一周第二&三单元>
    python mooc 3维可视化<第一周第一单元>
    conda 下配置环境
    第二周<岭回归>
    第二周<线性回归>
    第二周<导学/分类>
    iOS UILabel详解
    开始iOS 7中自动布局教程(一)
  • 原文地址:https://www.cnblogs.com/shenxiaohuang/p/11342620.html
Copyright © 2011-2022 走看看