传送门:http://acm.hdu.edu.cn/showproblem.php?pid=6343

Problem L. Graph Theory Homework

Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 262144/262144 K (Java/Others)
Total Submission(s): 1536    Accepted Submission(s): 830

Problem Description
There is a complete graph containing n vertices, the weight of the i-th vertex is wi.
The length of edge between vertex i and j (i≠j) is ⌊|wi−wj|−−−−−−−√⌋.
Calculate the length of the shortest path from 1 to n.
 
Input
The first line of the input contains an integer T (1≤T≤10) denoting the number of test cases.
Each test case starts with an integer n (1≤n≤105) denoting the number of vertices in the graph.
The second line contains n integers, the i-th integer denotes wi (1≤wi≤105).
 
Output
For each test case, print an integer denoting the length of the shortest path from 1 to n.
 
Sample Input
1
3
1 3 5
 
Sample Output
2
 
Source
 

题意概括:

给出每个点的权值,点与点之间的距离等于 √| wi-wj |  ,求起点到终点的最短距离。

解题思路:

一道伪装成图论的水题。

最短距离就是两点距离,因为如果中间放入其他点来进行更新路径是不会获得更短的路径的。

因为 √a + √b  > √(a+b) ;

AC code:

 #include<cstdio>
#include<algorithm>
#include<iostream>
#include<cstring>
#include<vector>
#include<queue>
#include<cmath>
#include<set>
#define INF 0x3f3f3f3f
#define LL long long
using namespace std;
int N; int myabs(int x)
{
if(x < ) return -x;
return x;
} int main()
{
int w, st, ed;
int T_case;
scanf("%d", &T_case);
while(T_case--){
scanf("%d", &N);
for(int i = ; i <= N; i++){
scanf("%d", &w);
if(i == ) st = w;
if(i == N) ed = w;
}
int ans = sqrt(myabs(st-ed));
printf("%d\n", ans);
}
return ;
}

2018 Multi-University Training Contest 4 Problem L. Graph Theory Homework 【YY】的更多相关文章

  1. 2018 Multi-University Training Contest 4 Problem K. Expression in Memories 【模拟】

    任意门:http://acm.hdu.edu.cn/showproblem.php?pid=6342 Problem K. Expression in Memories Time Limit: 200 ...

  2. 2018 Multi-University Training Contest 3 Problem F. Grab The Tree 【YY+BFS】

    传送门:http://acm.hdu.edu.cn/showproblem.php?pid=6324 Problem F. Grab The Tree Time Limit: 2000/1000 MS ...

  3. HDU 6343 - Problem L. Graph Theory Homework - [(伪装成图论题的)简单数学题]

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=6343 Time Limit: 2000/1000 MS (Java/Others) Memory Li ...

  4. HDU 6343.Problem L. Graph Theory Homework-数学 (2018 Multi-University Training Contest 4 1012)

    6343.Problem L. Graph Theory Homework 官方题解: 一篇写的很好的博客: HDU 6343 - Problem L. Graph Theory Homework - ...

  5. 2018 Multi-University Training Contest 4 Problem E. Matrix from Arrays 【打表+二维前缀和】

    任意门:http://acm.hdu.edu.cn/showproblem.php?pid=6336 Problem E. Matrix from Arrays Time Limit: 4000/20 ...

  6. 2018 Multi-University Training Contest 4 Problem B. Harvest of Apples 【莫队+排列组合+逆元预处理技巧】

    任意门:http://acm.hdu.edu.cn/showproblem.php?pid=6333 Problem B. Harvest of Apples Time Limit: 4000/200 ...

  7. 2018 Multi-University Training Contest 4 Problem J. Let Sudoku Rotate 【DFS+剪枝+矩阵旋转】

    任意门:http://acm.hdu.edu.cn/showproblem.php?pid=6341 Problem J. Let Sudoku Rotate Time Limit: 2000/100 ...

  8. 2017 Multi-University Training Contest - Team 9 1003&&HDU 6163 CSGO【计算几何】

    CSGO Time Limit: 20000/10000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others)Total Subm ...

  9. 华农oj Problem L: CreatorX背英语【STL】

    Problem L: CreatorX背英语 Time Limit: 1 Sec Memory Limit: 64 MB Submit: 53 Solved: 36 [Submit][Status][ ...

随机推荐

  1. 【JSON.parse()和JSON.stringify()】

    var str = '{"name":"huangxiaojian","age":"23"}' 结果: JSON.par ...

  2. CXF - 拦截器获取调用方法

    没想到要弄这么一个东西. 起初只是想用interceptor记录一下webservice调用日志,后来却被要求在页面展示. 展示容易,但只是展示webservice的地址无法让用户从中明白什么. 那么 ...

  3. 解决github无法访问的问题

     gitbub是外网,经常会遇到访问不了的问题,并且有时能访问也网速好慢. 解决这个问题的方法是 更改hosts文件,地址: C:\Windows\System32\Drivers\etc 我在hos ...

  4. javaweb servlet jsp简单笔记

    第二章: 1: web 俗称 : 万维网  www 2: web开发 的三大核心: HTML(网页) ,URL(定位),HTTP:(协议) 页面的分类: 静态页面: html+css 动态页面:jsp ...

  5. css样式的优先顺序

    一.css样式的权重:!important(1000+) > 内联样式(  1000 ) > ID选择器(100 ) > 类选择器(10) > 标签选择器( 1 ) > ...

  6. 动画演示10个有趣但毫无用处的Linux命令

    Linux最强大的一个特征就是它有大量的各种小命令工具,这也可以称做是它最有趣的一个地方了.在这些大量的有用的命令和脚本中,你会发现有少部 分命令工具不那么有用的——如果你不愿意说是完全没用处的话.你 ...

  7. python SyntaxError: EOL while scanning string literal

    错误原因是,字符串以 \ 结尾 或者字符串缺少引号. 写代码拼接windows 路径出现这个错误, 查资料才知道 python中字符串不能以 \ 结尾 我的代码如下 import os dirname ...

  8. GitHub教程(一) 使用指南

    刚进公司上班的时候,技术总监让我熟悉一下Git(分布式版本控制工具)操作命令和GitHub(代码托管平台),说实话之前我也没有具体使用过Git工具,但是GitHub我还是注册过账号的.在练习将本地仓库 ...

  9. 【NLP_Stanford课堂】拼写校正

    在多种应用比如word中都有拼写检查和校正功能,具体步骤分为: 拼写错误检测 拼写错误校正: 自动校正:hte -> the 建议一个校正 建议多个校正 拼写错误类型: Non-word Err ...

  10. 【NLP_Stanford课堂】语言模型3

    一.产生句子 方法:Shannon Visualization Method 过程:根据概率,每次随机选择一个bigram,从而来产生一个句子 比如: 从句子开始标志的bigram开始,我们先有一个( ...