【多校2018#4】HDU6343 Problem L. Graph Theory Homework
题面在这里
因为当\(a,b\gt 0\)时,\(\sqrt a + \sqrt b \gt \sqrt{a+b}\)
所以直接从1走到n就好了
示例程序:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16
| #include<cstdio> #include<cmath> #include<algorithm> #define _abs(x) ((x)>0?(x):-(x)) using namespace std;
const int maxn=100005; int tst,n,a[maxn]; int main(){ for (scanf("%d",&tst);tst;tst--){ scanf("%d",&n); for (int i=1;i<=n;i++) scanf("%d",&a[i]); printf("%d\n",(int)sqrt(_abs(a[1]-a[n]))); } return 0; }
|