2018 Multi-University Training Contest 4 Problem L. Graph Theory Homework 【YY】
传送门: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
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.
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).
题意概括:
给出每个点的权值,点与点之间的距离等于 √| 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】的更多相关文章
- 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 ...
- 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 ...
- 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 ...
- 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 - ...
- 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 ...
- 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 ...
- 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 ...
- 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 ...
- 华农oj Problem L: CreatorX背英语【STL】
Problem L: CreatorX背英语 Time Limit: 1 Sec Memory Limit: 64 MB Submit: 53 Solved: 36 [Submit][Status][ ...
随机推荐
- MYSQL连接字符串参数解析(解释)
被迫转到MySQL数据库,发现读取数据库时,tinyint类型的值都被转化为boolean了,这样大于1的值都丢失,变成true了.查阅资料MySQL中无Boolean类型,都是存储为tinyint了 ...
- Linux学习笔记之(2)~linux目录树概览和说明
献给知道mono,了解Jexus,对.net混搭技术感兴趣的朋友. linux目录树如下: 详解:/bin: 系统有很多放置执行档的目录,但/bin比较特殊.因为/bin放置的是在单人维护模式下还能够 ...
- golang学习之文件上传
首先是上传页面upload.html: <!doctype html> <html> <head> <meta charset="utf-8&quo ...
- 解决maven项目中,缺少 maven dependencies
因为项目需要将普通项目转换为maven项目,在右键 ’项目‘configure 后,添加maven后,发现缺少 maven dependencies,于是从网上找了一些处理措施,大体上是在.class ...
- EasyUI datebox 日期范围 日期关联
jQuery EasyUI 1.4.5 html: <label>提交日期:</label> <input id="startDate" name=& ...
- js判断值是否是数字
js如何判断值是否是数字 1. isNaN()方法2. 正则表达式var re = /^[0-9]+.?[0-9]*$/; //判断字符串是否为数字 //判断正整数 /^[1-9]+[0-9]*]*$ ...
- flask接收前台的ajax的post数据
html <!DOCTYPE html><html lang="en"><head> <meta charset="UTF-8& ...
- listview cacheColorHint,listSelector属性
ListView是常用的显示控件,默认背景是和系统窗口一样的透明色,如果给ListView加上背景图片,或者背景颜色时,滚动时listView会黑掉, 原因是,滚动时,列表里面的view重绘时,用的依 ...
- 电脑护眼小软件f.lux
f.lux这软件用了能不能保护好视力不好说,反正我是用了以后这么多年一直都在用,狠不下心删去.至少安装后能让心里多一些安全感! 以前老控制不住长期坐在电脑前不动,太需要有这类软件来养护.用了没太明显的 ...
- css3 background-sizing 属性,捎带 background-repeat 属性
background-sizing: contain: 在指定大小的容器内把图像按照图像本身长宽比扩展到最大尺寸,有可能有留白 cover: 在指定大小的容器内,把图像按照图像本身的长宽比扩展到足够大 ...