ural 2065 - Different Sums

来源:互联网 发布:python web 开发 编辑:程序博客网 时间:2024/04/30 14:08

题意:给出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;}


0 0