zoukankan      html  css  js  c++  java
  • April Fools Day Contest 2016 E. Out of Controls

    E. Out of Controls

    题目连接:

    http://www.codeforces.com/contest/656/problem/E

    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 ≤ N ≤ 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. aij = aji, aii = 0, 1 ≤ aij ≤ 100 for i ≠ j.

    Output

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

    Sample Input

    3
    0 1 1
    1 0 4
    1 4 0

    Sample Output

    2

    Hint

    题意

    给你一个邻接矩阵,然后让你输出其中最大的最短路是多少

    但是你不能使用

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

    这些函数名字

    题解:

    可以用三目运算符嘛,然后递归的去做就好了。

    代码

    #include<bits/stdc++.h>
    using namespace std;
    
    int a[15][15];
    int res;
    int n;
    int get(int x,int y)
    {
        cin>>a[x][y];
        return y==n?(x==n?1:get(x+1,1)):get(x,y+1);
    }
    int geta(int x,int y)
    {
        res=max(res,a[x][y]);
        return y==n?(x==n?1:geta(x+1,1)):geta(x,y+1);
    }
    int flyod(int x,int y,int k)
    {
        a[x][y]=min(a[x][y],a[x][k]+a[k][y]);
        y++;
        y==n+1?(x++,y=1):0;
        x==n+1?(x=1,k++):0;
        k<=n?flyod(x,y,k):0;
    }
    int main()
    {
        cin>>n;
        get(1,1);
        flyod(1,1,1);
        geta(1,1);
        cout<<res<<endl;
    }
  • 相关阅读:
    JSP/Servlet相关
    mysql 相关问题解决
    Git常用
    利用JDBC连接MySQL并使用MySQL
    memcache、redis原理对比
    Python 2.7.x 和 3.x 版本的重要区别
    python 单例模式
    python 装饰器原理及用法
    python 冒泡排序
    python 迭代器和生成器
  • 原文地址:https://www.cnblogs.com/qscqesze/p/5348114.html
Copyright © 2011-2022 走看看