题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=6343
题意:一个完全图,给出n个点的权值,任意边的权值为 ,求出从1点走到n点的最短距离。
题解:直接从1号点走到最后一个点就行了,因为经过中继点越多,走的距离就越多。
代码:
#include<cstdio>
#include<algorithm>
#include<cstring>
#include<cmath>
using namespace std;
int main()
{
int ncase;
scanf("%d",&ncase);
while(ncase--)
{
int m;
scanf("%d",&m);
int p0;
scanf("%d",&p0);
int p1=p0;
for(int i=2;i<=m;i++)
scanf("%d",&p1);
p0=abs(p1-p0);
printf("%d\n",(int)sqrt(p0));
}
return 0;
}