『题解』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 ...
随机推荐
- 「面试高频」二叉搜索树&双指针&贪心 算法题指北
本文将覆盖 「字符串处理」 + 「动态规划」 方面的面试算法题,文中我将给出: 面试中的题目 解题的思路 特定问题的技巧和注意事项 考察的知识点及其概念 详细的代码和解析 开始之前,我们先看下会有哪些 ...
- ES6——新增数据结构Set与Map的用法
ES6 提供了新的数据结构 Set以及Map,下面我们来一一讲解. 一.Set 特性 似于数组,但它的一大特性就是所有元素都是唯一的,没有重复. 我们可以利用这一唯一特性进行数组的去重工作. 1.单一 ...
- 微信退款(APP和公众号一样)
/** * 将xml转为array * @param string $xml xml字符串 * @return array 转换得到的数组 */ public function xml2array($ ...
- golang 服务平滑重启小结
背景 golang 程序平滑重启框架 supervisor 出现 defunct 原因 使用 master/worker 模式 背景 在业务快速增长中,前期只是验证模式是否可行,初期忽略程序发布重启带 ...
- Django-debug-toolbar(调试使用)
Django-debug-toolbar django-debug-toolbar 是一组可配置的面板,可显示有关当前请求/响应的各种调试信息,并在单击时显示有关面板内容的更多详细信息. https: ...
- 渗透测试-基于白名单执行payload--Regsvr32
复现亮神课程 基于白名单执行payload--Regsvr32 0x01 Regsvr32 Regsvr32命令用于注册COM组件,是 Windows 系统提供的用来向系统注册控件或者卸载控件的命令, ...
- [JZOJ5459]【NOIP2017提高A组冲刺11.7】密室
Description 小X 正困在一个密室里,他希望尽快逃出密室.密室中有N 个房间,初始时,小X 在1 号房间,而出口在N 号房间.密室的每一个房间中可能有着一些钥匙和一些传送门,一个传送门会单向 ...
- Flyway 助力数据库脚本自动化管理攻略
原文地址:梁桂钊的博客 博客地址:http://blog.720ui.com 欢迎关注公众号:「服务端思维」.一群同频者,一起成长,一起精进,打破认知的局限性. 今天,探讨一个有趣的话题:我们可以通过 ...
- 详解Java Web项目启动执行顺序
一. web.xml加载过程(步骤): 启动web项目,容器(如Tomcat.Apache)会去读取它的配置文件web.xml 中的两个节点,context-param和listener. 紧接着,容 ...
- Codeforces--Books Exchange (hard version)
题目链接http://codeforces.com/contest/1249/problem/B2 .并查集思想,将数分成多个集合,每个集合的大小就是一轮的所需天数. Map[i]存储数据. flag ...