題意:給出n、m,要求用m個不同的數字組成n個數字的序列,使得不同區間不同的區間和的不同數值數量最少。
前m個數字0,1,-1,2,-2……剩下的部分全補0.
#include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>
using namespace std;
int main() {
int n, k, i, j, m;
while(~scanf("%d%d", &n, &k)) {
m = 0;
for(i = 0; i < n; i++) {
if(i)
printf(" ");
if(k) {
k--;
printf("%d", m);
if(m <= 0)
m = 1 - m;
else m = -m;
}
else printf("0");
}
printf("\n");
}
return 0;
}