ural- 2065 Different Sums

这个题生成一个序列,使这个序列满足,题目,昨天比赛的时候,直接写了一个正负的,我觉得应该可以然后,然后过不了样例,那个时候大脑已经有一点不反应了,然后我就看到没有输出任意一组样例  If there are multiple possible answers, you may print any of them.就是这句话,然后雪崩,比赛完了交了一发,对了,自己的英语能力是真的差劲,昨天都错了两个题

Alex is a very serious mathematician and he likes to solve serious problems. For example, this problem.
You are to construct an array of  n integers in which the amount of different integers is not less than  k. Among all such arrays you have to construct the one with the minimal amount of different sums on non-empty subarrays. In other words, lets compute the sums of every non-empty subarray and remove repeating sums. You have to minimize the number of remaining sums.
Input
In the only line of input there are two integers  nk (1 ≤  k ≤  n ≤ 500), separated by a space.
Output
Print  n integers separated by spaces — the answer for the problem. All the numbers must not be greater than 10  6 by absolute value. It is guaranteed that there exists an optimal solution with numbers up to 10  5 by absolute value. If there are multiple possible answers, you may print any of them.
Example
input output
1 1
-987654
3 2
0 7 0

Notes

Let’s take a closer look on the second sample. We will denote the sum on the segment [  lr] by  sumlr) (elements are numbered starting with 1).  sum(1, 1) = sum(3, 3) = 0,  sum(1, 2) =  sum(1, 3) =  sum(2, 2) =  sum(2, 3) = 7, so there are only two different sums.
#include <iostream>
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <algorithm>
#include <vector>
#include <map>
#include <math.h>
#include <stack>
#define LL long long
using namespace std;
const int INF = 0x3f3f3f3f;
const int maxn = 500 + 10;
int dir[4][2] = {{1,0},{0,1},{-1,0},{0,-1}};
int n,k;
int a[maxn];
int main()
{
    scanf("%d%d",&n,&k);
    int cur=0;
    for(int i=1;; ++i)
    {
        if(cur==k-1)break;
        a[cur]=i;
        cur++;
        if(cur==k-1)break;
        a[cur]=-i;
        cur++;
    }
    for(int i=0; i<n; ++i)
    {
        if(i == 0)
            printf("%d",a[i]);
        else
             printf(" %d",a[i]);
    }
    return 0;
}


  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值