题目链接:https://vjudge.net/problem/HDU-1673
读懂你就知道...找出极差,乘上2倍就是最小距离
1 #include <cstdio> 2 #include <cstring> 3 #include <cmath> 4 #include <iostream> 5 #include <algorithm> 6 #include <string> 7 #include <cstdlib> 8 9 using namespace std; 10 11 int main() 12 { 13 int t,n,i,temp; 14 scanf("%d",&t); 15 while(t--) 16 { 17 scanf("%d",&n); 18 int maxNum=0,minNum=100000; 19 for(i=1;i<=n;i++) 20 { 21 scanf("%d",&temp); 22 if(temp>maxNum) maxNum=temp; 23 if(temp<minNum) minNum=temp; 24 } 25 printf("%d\n",(maxNum-minNum)*2); 26 } 27 }