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);
    }
    
  • 相关阅读:
    vs2019+GLFW+GLAD出现无法解析的外部符号
    图的着色算法
    Head First C# 实验室2(冒险游戏)
    击中和击不中变换
    开运算和闭运算
    膨胀与腐蚀
    两数相加(C#数据结构和算法练习)
    C# 特性和索引(C#学习笔记06)
    C# 索引器(C#学习笔记05)
    C# yield checked,unchecked lock语句(C#学习笔记04)
  • 原文地址:https://www.cnblogs.com/shenxiaohuang/p/11342620.html
Copyright © 2011-2022 走看看