传送门: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. .net HttpClient的使用

    在程序用调用 Http 接口.请求 http 资源.编写 http 爬虫等的时候都需要在程序集中进行 Http 请 求.  很多人习惯的 WebClient.HttpWebRequest 在 TPL ...

  2. Spring.Net IOC基本应用和在MVC4中的应用

    1.Spring.Net的IOC简单应用 新建一个解决方案添加一个控制台应用程序和一个业务层一个业务层的接口层,通过配置,让控制台应用程序调业务层的方法 1)新建如下图所示,BLL为业务层,通过Spr ...

  3. 自定义控件实现-今日头条Android APP图集效果

    前提 产品有个新需求,类似今日头条的图集效果 大致看了下UI,大致就是ViewPager,横向滑动切换图片,纵向滑动移动图片,纵向超过一定距离,图片飞出,图集淡出动画退出,支持图片的双击放大. 思路 ...

  4. java-IO小记

    说来惭愧,工作一年多了,对io仍然不是很了解.不仅是io,还有网络,还有多线程.shame!!! 接下来的日子里,先搞多线程,再搞io,再搞网络,半年内一定要完成! 好了,今天终于搞懂了outputS ...

  5. package和package-lock区别;dependencies和devDependencies区别

    package和package-lock package.json: 主要用来定义项目中需要依赖的包 package-lock.json: 在 npm install时候生成一份文件,用以记录当前状态 ...

  6. 读ios开发有感——建立APP开发体系

    前言:ios开发和现在的大前端.跨端开发在底层上的道理是相通的,因此通过学习ios开发,可以形成对APP开发体系的理解. 一.app开发的知识体系 基础 应用开发 原理 原生与前端 二.基础模块 按照 ...

  7. 爬虫之Beautifulsoup的基本实用

    基本方法如下: # soup.a 只能找到第一个符合要求的标签 # soup.a.attrs 获取a所有的属性和属性值 # soup.a.attrs['href'] 获取href属性 # soup.a ...

  8. 关于开发Cesium造成的电脑风扇狂飙的问题

    最近在开发Cesium的项目,每次一打开浏览器渲染3D 模型.风扇就狂飙起来,进任务管理器查看发现集显使用率100%,独显使用率0%.使用的是集显进行渲染.怪不得风扇会飙起来.既然知道问题所在,解决的 ...

  9. nginx: [emerg] bind() to 0.0.0.0:80 failed (98: Address already in use)解决方案

    前提:已经配置好静态IP以防万一,先安装好iptables服务(不管你装没装,先执行,免得后面添乱)[root@localhost ~]# yum install iptables-services[ ...

  10. 001服务注册与发现Eureka

    1.POM配置 和普通Spring Boot工程相比,仅仅添加了Eureka Server依赖和Spring Cloud依赖管理 <dependencies> <!--添加Eurek ...