您的位置:首页 > Web前端

URAL2065:Different Sums(找规律)

2017-03-02 17:57 375 查看


2065. Different Sums

Time limit: 1.0 second

Memory limit: 64 MB

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 n, k (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 106 by
absolute value. It is guaranteed that there exists an optimal solution with numbers up to 105 by absolute value. If there are multiple possible answers, you may print any of them.

Samples

inputoutput
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 [l,r] by sum(l,r) (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.

Problem Author: Nikita Sivukhin (prepared by Alexey Danilyuk, Nikita Sivukhin)
Problem Source: Ural Regional School Programming Contest 2015

Tags: none  (

hide tags for unsolved problems
)
题意:要求创造一个N个元素的数组,其中不同的元素有k种,且数组的子串和种类数最少。

思路:正负交替即可,多余的用0填充。

# include <iostream>
# include <cstdio>
# include <vector>
# include <algorithm>
using namespace std;
int main()
{
int n, k, a[501], j=0, t=1;
for(int i=0; i<=500; ++i)
{
if(!(i&1))
++j;
a[i] = j*t;
t = -t;
}
while(~scanf("%d%d",&n,&k))
{
for(int i=0; i<k-1; ++i)
printf("%d ",a[i]);
for(int i=k-1; i<n; ++i)
printf("0 ");
printf("\n");
}
return 0;
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: