『题解』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 \ne 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\n", ans);
}
『题解』Codeforces656E Out of Controls的更多相关文章
- 『题解』洛谷P1063 能量项链
原文地址 Problem Portal Portal1:Luogu Portal2:LibreOJ Portal3:Vijos Description 在\(Mars\)星球上,每个\(Mars\)人 ...
- 『题解』Codeforces1142A The Beatles
更好的阅读体验 Portal Portal1: Codeforces Portal2: Luogu Description Recently a Golden Circle of Beetlovers ...
- 『题解』Codeforces1142B Lynyrd Skynyrd
更好的阅读体验 Portal Portal1: Codeforces Portal2: Luogu Description Recently Lynyrd and Skynyrd went to a ...
- 『题解』洛谷P1993 小K的农场
更好的阅读体验 Portal Portal1: Luogu Description 小\(K\)在\(\mathrm MC\)里面建立很多很多的农场,总共\(n\)个,以至于他自己都忘记了每个农场中种 ...
- 『题解』洛谷P2296 寻找道路
更好的阅读体验 Portal Portal1: Luogu Portal2: LibreOJ Description 在有向图\(\mathrm G\)中,每条边的长度均为\(1\),现给定起点和终点 ...
- 『题解』洛谷P1351 联合权值
更好的阅读体验 Portal Portal1: Luogu Portal2: LibreOJ Description 无向连通图\(\mathrm G\)有\(n\)个点,\(n - 1\)条边.点从 ...
- 『题解』洛谷P2170 选学霸
更好的阅读体验 Portal Portal1: Luogu Description 老师想从\(N\)名学生中选\(M\)人当学霸,但有\(K\)对人实力相当,如果实力相当的人中,一部分被选上,另一部 ...
- 『题解』洛谷P1083 借教室
更好的阅读体验 Portal Portal1: Luogu Portal2: LibreOJ Portal3: Vijos Description 在大学期间,经常需要租借教室.大到院系举办活动,小到 ...
- 『题解』Codeforces9D How many trees?
更好的阅读体验 Portal Portal1: Codeforces Portal2: Luogu Description In one very old text file there was wr ...
随机推荐
- A-02 梯度下降法
目录 梯度下降法 一.梯度下降法详解 1.1 梯度 1.2 梯度下降法和梯度上升法 1.3 梯度下降 1.4 相关概念 1.4.1 步长 1.4.2 假设函数 1.4.3 目标函数 二.梯度下降法流程 ...
- RE-1 逆向分析基础
逆向分析基础 0x01-0x0C 本笔记使用汇编指令为x86架构下汇编指令,ARM架构汇编指令不做介绍 0x01. 关于RE 逆向工程(Reverse Engineering RE) 逆向分析方法: ...
- JavaScript ES6函数式编程(一):闭包与高阶函数
函数式编程的历史 函数的第一原则是要小,第二原则则是要更小 -- ROBERT C. MARTIN 解释一下上面那句话,就是我们常说的一个函数只做一件事,比如:将字符串首字母和尾字母都改成大写,我们此 ...
- 安卓控件 仪表盘控件 柱状图控件 曲线控件 xamarin.android 分类器 瓶子控件 报警控件 水箱控件 进度条控件等
本篇博客主要介绍一个控件库,HslControls.dll 的界面,这个控件库支持winform,winform的参考另一篇文章:https://www.cnblogs.com/dathlin/p/1 ...
- PHP array_unique
1.函数的作用:移除数组中重复的值 2.函数的参数: @params array $array @params int $sort_flag SORT_REGULAR : 通常方法比较(不改变类型) ...
- PHP array_reverse
1.函数的作用:将数组中的元素顺序反转 2.函数的参数: @params array $array 需要反转顺序的数组 @params $preversed_key 数值索引是否保持不变,非数值索引 ...
- .NET实时2D渲染入门·动态时钟
.NET实时2D渲染入门·动态时钟 从小以来"坦克大战"."魂斗罗"等游戏总令我魂牵梦绕.这些游戏的基础就是2D实时渲染,以前没意识,直到后来找到了Direct ...
- [GDKOI2016]染色大战
Description
- 常用函数-Linux文件操作
/************************************************************************ 函数功能:寻找文件夹下的某格式文件 std::vec ...
- VMware安装和linux(centos7)系统安装
下载centos系统ISO镜像 安装linux系统和winsdows安装系统一样,需要系统文件.浏览器访问centos官网进行下载,http://www.centos.org,因为是国外网站所有下载速 ...