传送门: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. asfda

    从事前端的朋友应该对"字体图标"这个词汇不陌生,为了适应越来越挑剔的屏幕,网页图标和简单图案使用.png来搭建已经基本上被淘汰了.取而代之的是使用css3和svg来绘制,而对于网页 ...

  2. Rabbit的直连交换机direct

    直连交换机类型为:direct.加入了路由键routingKey的概念. 就是说 生产者投递消息给指定交换机的指定路由键. 只有绑定了此交换机指定路由键的消息队列才可以收到消息. 生产者: packa ...

  3. unity3d之相机跟随人物

    一.第三人称视角 _1 先设置好相机与玩家之间的角度 给相机添加代码 using UnityEngine; using System.Collections; namespace CompletePr ...

  4. Angularjs之依赖注入

    一个对象通常有三种方式可以获得对其依赖的控制权: 在内部创建依赖: 通过全局变量进行引用: 在需要的地方通过参数进行传递 依赖注入是通过第三种方式实现的.比如: function SomeClass( ...

  5. safari兼容时间格式

    前提: 使用iview的DatePicker组件,保存时间后台接收时间戳 问题: safari中不支持2018-02-13这种格式转为时间戳会显示NaN 解决: new Date('2018/02/1 ...

  6. js原生获取css属性

    原文参考http://blog.csdn.net/lzding/article/details/46317777 1.写在dom上的属性,内联样式 <div id="box" ...

  7. jQuery对html元素取值与赋值

    以下总结了常用的jQuery选择器对html元素取值与赋值 Textbox:  var str = $('#txt').val(); $('#txt').val("Set Lbl Value ...

  8. Magisk+Xposed+Root switch+Pokémon GO

    If you follow Android Police, there's a good chance you've got a rooted device, whether it be an eas ...

  9. c#调用c++制作的基于mfc的ocx控件

    原文:http://blog.csdn.net/yhhyhhyhhyhh/article/details/51286926 原文中有问题部分已修改. c#调用c++制作的基于mfc的ocx控件     ...

  10. SQL Server ->> Sparse File(稀疏文件)

    Sparse File(稀疏文件)不是SQL Server的特性.它属于Windows的NTFS文件系统的一个特性.如果某个大文件中的数据包含着大量“0数据”(这个应该从二进制上看),这样的文件就可以 ...