C - Different Sums URAL - 2065 ----思维题
2017-04-28 20:33
363 查看
C - Different Sums
URAL- 2065
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 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 [ 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.
题目链接:https://cn.vjudge.net/contest/160744#problem/C
我和UMR在比赛的时候竟然忘记了负数。。。mdzz
题目的意思是说让你构造一个序列,使得子序列的和的个数最小,序列中不同的数的个数不小于k个。
最后出来的序列0,1,-1,2,-2.....
代码:
#include <bits/stdc++.h>
#define zero(x) (((x)>0?(x):(-x))<eps)
using namespace std;
const int MAXN=500+7;
int n,k;
int num[MAXN];
int main(){
scanf("%d%d",&n,&k);
int cnt=0;
for(int i=1;;++i){
if(cnt==k-1)break;
num[cnt++]=i;
if(cnt==k-1)break;
num[cnt++]=-i;
if(cnt==k-1)break;
}
for(int i=0;i<n;++i){
if(i)printf(" ");
printf("%d",num[i]);
}
return 0;
}
相关文章推荐
- ural 2065 - Different Sums
- URAL2065:Different Sums(找规律)
- URAL 2065 Different Sums (找规律)
- 思维题 URAL 1409 Two Gangsters
- G - Caterpillars URAL - 2064 ----思维题
- ural 1048. Superlong Sums 模拟
- HDU 5847 Different Sums (构造+数学+打表)
- ural 2025. Line Fighting -思维题
- Ural 2003: Simple Magic(数论&思维)
- ural 1542 字典树(思维)
- POJ 2602|URAL 1048|Superlong Sums|高精度加法
- Ural2004: Scientists from Spilkovo(德布鲁因序列&思维)
- ural 2065. Different Sums
- URAL 1048 Superlong Sums
- C. Bear and Different Names----思维水题
- Uva 10795 A Different Task 解题报告(递归+思维)
- Ural 2067 Friends and Berries 【思维】
- CF#405 C. Bear and Different Names (思维题)
- G - Hard Rock URAL - 2069 ----思维题
- URAL 1409 Two Gangsters (开放思维)