A
手玩一下就能出来的东西吧,粘个核心代码。
if(x > y) ww(x), wl;
else if(x + k >= y) ww(y), wl;
else ww(y * 2 - x - k), wl;
B
观察性质,一定是将数组排序后,从 \(1 \sim n\) 为横坐标,从 \(n + 1 \sim n * 2\) 为纵坐标。所得距离应为横坐标之差的和和纵坐标之差的和。
核心代码。(手玩一下也能出来。)
read(n);
sum = 0;
fos(i, 1, n * 2) read(a[i]);
sort(a + 1, a + n * 2 + 1);
fos(i, 2, n) sum += a[i] - a[i - 1];
fos(i, n + 2, n * 2) sum += a[i] - a[i - 1];
ww(sum), wl;
fos(i, 1, n) ww(a[i]), ws, ww(a[2 * n - i + 1]), wl;
标签:CF1895,fos,sum,wl,ww,手玩
From: https://www.cnblogs.com/carp-oier/p/CF1895.html