AT185 2点間距離の最大と最小 题解
这道题我看题解区讲的都很谜
所以我来发图解释一下
如图(SketchPad画的有点丑)
现在有
我们要求①~⑤的最大距离,就是把他们的距离加起来
那么最小距离呢?
如果最长的边长度
我们看一下图二,就是这样,所以最小距离为
如果最长的边的长度
我们看一下图三,这里4和5的距离改成了
所以最小距离就是最长的边的长度
即
接下来贴代码↓
#include<bits/stdc++.h>
using namespace std;
signed main()
{
int n, tot=0, maxx=0;
scanf("%d",&n);
for (int i=1,x; i<=n; i++)
{
scanf("%d",&x);
tot+=x;
maxx=max(maxx, x);
}
printf("%d\n",tot);
tot-=maxx;
if (tot>=maxx)
puts("0");
else
printf("%d\n",maxx-tot);
return 0;
}