『题解』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 ...
随机推荐
- SpringBootSecurity学习(23)前后端分离版之OAuth2.0 其它模式
密码模式 前面介绍了授权码模式和刷新令牌两种获取最新令牌的方法,下面来看一下其它模式.首先看密码模式,我们默认配置的三种模式中其实就包含密码模式的支持: 因此我们启动项目,直接使用密码模式即可,访问地 ...
- vue父子组件钩子函数的执行顺序
加载渲染过程 父beforeCreate->父created->父beforeMount->子beforeCreate->子created->子beforeMount-& ...
- KafkaStream-高级别API
使用Streams DSL构建一个处理器拓扑,开发者可以使用KStreamBuilder类,它是TopologyBuilder的扩展.在Kafka源码的streams/examples包中有一个简单的 ...
- centos7升级openssl、openssh常见问题及解决方法
升级至openssl 1.1.1版本 升级至openssh 8.0版本 openssl version -a 当前查看版本 一.安装telnet (以防升级失败,连不上服务器,建议弄) #查看是否 ...
- Python_函数做字典的值
当需要用到3个及以上的if...elif...else时就要考虑该方法进行简化 通过将函数名称当做字典的值,利用字典的关键字查询,可以快速定位函数,进行执行 [场景]用户查询信息,输入fn查询,执行对 ...
- 如何成长为一名合格的web前端开发工程师呢?
前端开发工程师不仅仅要掌握一些基础的美工设计等还要懂得网页设计类的HTML JavaScript和css,这三种能力缺一不可,虽不要求你特别的精通,但至少要熟练的掌握,能够运用自己所了解的这些技术和知 ...
- 一文了解Mysql
文章原创于公众号:程序猿周先森.本平台不定时更新,喜欢我的文章,欢迎关注我的微信公众号. Redis系列到上一篇已经全部结束了,从本篇开始进入Mysql系列文章专题.本篇作为Mysql系列专题的开篇文 ...
- openssl之DH(Diffie–Hellman)加密
//加密机制初始化 g_HDMgr.init(); //对方的public key BIGNUM* peerPubKey = NULL; peerPubKey = BN_bin2bn((unsigne ...
- MySQL注入--Payload
MySQL注入--Payload Mirror王宇阳 2019-10-22 SQL的注入流程一般如下: 1.判断是否有SQL注入漏洞(判断注入点) 2.判断数据库的系统架构.数据库名.web应用类型等 ...
- python中如何通过报错信息定位问题(异常传播轨迹)
class SelfException(Exception): pass def main(): firstMethod() def firstMethod(): secondMethod() def ...