HDU 6343 Problem L. Graph Theory Homework

版权声明:布呗之路的守望者 https://blog.csdn.net/hypHuangYanPing/article/details/81876948
/**
HDU 6343 Problem L. Graph Theory Homework
链接:http://acm.hdu.edu.cn/showproblem.php?pid=6343
题意:给你n个点 每个点都对应一个权值wi  从当前节点到任意一个节点j的的路径为sqrt((wi-wj));
问:1-->n的最短路径为多少 ;
三角形 两边之和必定是大于第三边的 因此ans = sqrt((w1-wn));
*/
#include<bits/stdc++.h>
#define ll long long 
using namespace std;

const int maxn=1e6+7;
int a[maxn];

int main (){
    int t,n;cin>>t;
    while(t--){
        scanf("%d",&n);
        for(int i=1;i<=n;i++) scanf("%d",&a[i]);
        printf("%d\n",(int)sqrt(fabs(a[n]-a[1])));
    }
    return 0;
}

猜你喜欢

转载自blog.csdn.net/hypHuangYanPing/article/details/81876948