第二题的代码有个地方有个小问题,我修正了下,但是编辑原文有点问题,我把修正后的代码放到这里,原文博客已经修正了
#include <bits/stdc++.h>
using namespace std;
typedef long long LL;
int main()
{
int n, k;
while (~scanf("%d%d", &n, &k)) {
vector<LL> arr;
LL theMin = 0x3f3f3f3f3f;
for (int i = 0; i < n; i++) {
LL x;
scanf("%lld", &x);
arr.push_back(x);
theMin = min(theMin, x);
}
if (arr[k - 1] == theMin) {
for (vector<LL>::size_type i = 0; i < arr.size(); i++) {
if (i == k - 1)
printf("%lld", 1LL * theMin * n);
else
printf("%lld", arr[i] - theMin);
putchar(i == arr.size() - 1 ? '\n' : ' ');
}
} else {
int i, d;
for (i = k - 1, d = 0; theMin != arr[(i + n) % n]; i--, d++)
arr[(i + n) % n] = arr[(i + n) % n] - theMin - 1;
arr[(i + n) % n] = 1LL * theMin * n + d;
if ((i + n) % n != k) {
for (--i; (i + n) % n != k; i--)
arr[(i + n) % n] = arr[(i + n) % n] - theMin;
arr[(i + n) % n] = arr[(i + n) % n] - theMin;
}
for (vector<LL>::size_type i = 0; i < arr.size(); i++)
printf("%lld%c", arr[i], i == arr.size() - 1 ? '\n' : ' ');
}
}
return 0;
}