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 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 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

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] bysum(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
Difficulty: 195
 
题意:构造一个数列,使得它们的区间和的种类最少,其中数列中不同的数的数目不少于k
分析:
首先0对于答案无影响。
那么最少的就是类似这样的数列
...........3 -2 1 -1 2 -3......
 
 /**
Create By yzx - stupidboy
*/
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <cmath>
#include <deque>
#include <vector>
#include <queue>
#include <iostream>
#include <algorithm>
#include <map>
#include <set>
#include <ctime>
#include <iomanip>
using namespace std;
typedef long long LL;
typedef double DB;
#define MIT (2147483647)
#define INF (1000000001)
#define MLL (1000000000000000001LL)
#define sz(x) ((int) (x).size())
#define clr(x, y) memset(x, y, sizeof(x))
#define puf push_front
#define pub push_back
#define pof pop_front
#define pob pop_back
#define mk make_pair inline int getInt()
{
int ret = ;
char ch = ' ';
bool flag = ;
while(!(ch >= '' && ch <= ''))
{
if(ch == '-') flag ^= ;
ch = getchar();
}
while(ch >= '' && ch <= '')
{
ret = ret * + ch - '';
ch = getchar();
}
return flag ? -ret : ret;
} int n, k;
deque<int> ans; inline void input()
{
cin >> n >> k;
k--;
} inline void solve()
{
for(int i = ; * i <= k; i++)
if(i & ) ans.puf(-i), ans.pub(i);
else ans.puf(i), ans.pub(-i);
if(k & ) ans.pub((((k / ) & ) ? - : ) * (k / + ));
for(int i = k / + ; i <= n; i++)
ans.pub();
for(int i = ; i < n - ; i++) cout << ans[i] << ' ';
cout << ans[n - ] << "\n";
} int main()
{
ios::sync_with_stdio();
input();
solve();
return ;
}

ural 2065. Different Sums的更多相关文章

  1. URAL 2065 Different Sums (找规律)

    题意:构造一个数列,使得它们的区间和的种类最少,其中数列中不同的数的数目不少于k. 析:我们考虑0这个特殊的数字,然后0越多,那么总和种类最少,再就是正负交替,那么增加0的数量. 代码如下: #pra ...

  2. 【找规律】URAL - 2065 - Different Sums

    就让0出现得尽可能多嘛……大概感受一下就是这样…… 0 0 ... 0 0 0 0 4 -4 3 -3 2 -2 1 -1 #include<cstdio> using namespace ...

  3. URAL - 2065 Different Sums (思维题)

    题意: 给n和k,让你用不小于 k 个不同的数字构成一个长度为n的序列,使得序列中不同的区间和的数目最小. n,k<=500 k-1个数填一些数字的一正一负,这样有些区间和为0. 剩下的都填0. ...

  4. ural 1217. Unlucky Tickets

    1217. Unlucky Tickets Time limit: 1.0 secondMemory limit: 64 MB Strange people live in Moscow! Each ...

  5. Poj OpenJudge 百练 2602 Superlong sums

    1.Link: http://poj.org/problem?id=2602 http://bailian.openjudge.cn/practice/2602/ 2.Content: Superlo ...

  6. [LeetCode] Find K Pairs with Smallest Sums 找和最小的K对数字

    You are given two integer arrays nums1 and nums2 sorted in ascending order and an integer k. Define ...

  7. UVA-11997 K Smallest Sums

    UVA - 11997 K Smallest Sums Time Limit: 1000MS   Memory Limit: Unknown   64bit IO Format: %lld & ...

  8. POJ3187Backward Digit Sums[杨辉三角]

    Backward Digit Sums Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 6350   Accepted: 36 ...

  9. ural One-two, One-two 2

     One-two, One-two 2 Time Limit:2000MS     Memory Limit:65536KB     64bit IO Format:%I64d & %I64u ...

随机推荐

  1. python基础——装饰器

    python基础——装饰器 由于函数也是一个对象,而且函数对象可以被赋值给变量,所以,通过变量也能调用该函数. >>> def now(): ... print('2015-3-25 ...

  2. 【翻译十九】-java之执行器

    Executors In all of the previous examples, there's a close connection between the task being done by ...

  3. Swing布局基础

    虽然很简单,但还是记录一下,以备复查. 1.BorderLayout ,这是JFrame的默认布局方式,基于此的新组件,例如BUTTON,可以放在东西南北中的某一个位置,如果不指定,则默认是中央.中央 ...

  4. git push 使用总结

    git push命令用于将本地分支的更新,推送到远程主机.它的格式与git pull命令相仿. $ git push <远程主机名> <本地分支名>:<远程分支名> ...

  5. oracle sql rank dense_rank row_number fisrt last

    測試表emp

  6. js判断当前的访问是手机还是电脑

    <script type="text/javascript"> //平台.设备和操作系统 var system ={ win : false, mac : false, ...

  7. IIS常见错误

    1.IIS7运行时访问报错,先安装VS,再启用的IIS,那么需要为IIS进行注册,在VS工具命令行中执行“aspnet_regiis.exe -ir -enable”即可 2.错误“未能加载文件或程序 ...

  8. hdu 3032 sg打表找规律 *

    有n堆石子,alice先取,每次可以选择拿走一堆石子中的1~x(该堆石子总数) ,也可以选择将这堆石子分成任意的两堆.alice与bob轮流取,取走最后一个石子的人胜利. 打表代码: #include ...

  9. [Eclipse][SVN] 在eclipse上安装SVN

    以前装过好多次SVN,始终没有一次把安装过程记录下来,这次新装机器,安装SVN插件时一波三折,记录下来免得以后又忘记了.   方法一: 1. 直接通过后台添加URL通过互联网进行安装,直接上图: 2. ...

  10. UML 类关系及画法

    1 泛化 [泛化关系]:是一种继承关系,表示一般与特殊的关系,它指定了子类如何特化父类的所有特征和行为.例如:老虎是动物的一种,即有老虎的特性也有动物的共性. [箭头指向]:带三角箭头的实线,箭头指向 ...