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. HttpClient 3.X 4.3 4.x超时设置

    HttpClient 4.3.HttpClient这货和Lucene一样,每个版本的API都变化很大,这有点让人头疼.就好比创建一个HttpClient对象吧,每一个版本的都不一样, 3.X是这样的 ...

  2. ASP.NET Global 全局事件处理

    添加Global文件,名字不要改 Global类说明: using System; using System.Collections.Generic; using System.IO; using S ...

  3. Android屏幕旋转总结

    转自:http://www.myexception.cn/operating-system/1452058.html 1. ProjectConifg.mk中定义宏MTK_LCM_PHYSICAL_R ...

  4. **PHP中替换换行符

    PHP中替换换行符 php 不同系统的换行不同系统之间换行的实现是不一样的linux 与unix中用 \nMAC 用 \rwindow 为了体现与linux不同 则是 \r\n所以在不同平台上 实现方 ...

  5. Delphi中函数定义和声明的位置

    当函数(或过程)A定义在函数(或过程)B之前,那么函数B就可以调用函数A,并且编译成功,例如下面的 procedure TForm1.btn1Click(Sender: TObject); 和   f ...

  6. Bootstrap 排版 笔记

    Bootstrap 使用 Helvetica Neue. Helvetica. Arial 和 sans-serif 作为其默认的字体栈. 使用 Bootstrap 的排版特性,您可以创建标题.段落. ...

  7. 快速熟悉python 下使用mysql(MySQLdb)

    首先你需要安装上mysql和MySQLdb模块(当然还有其他模块可以用),这里我就略过了,如果遇到问题自行百度(或者评论在下面我可以帮忙看看) 这里简单记录一下自己使用的学习过程: 一.连接数据库 M ...

  8. 安装VS2010水晶报表插件

    Visual Studio 2010默认不带水晶报表,需要安装一个水晶报表插件,首先下载此插件: http://downloads.businessobjects.com/akdlm/cr4vs201 ...

  9. codeforces Round#380 div2

    1.字符串替换ogo+go…换成*** 思路:找ogo记录g位置,做初步替换和标记,非目标字母直接输出, 间隔为2的判断是否一个为标记g,一个为非标记做***替换 #include<iostre ...

  10. HDU 3364 Lanterns 高斯消元

    Lanterns Problem Description   Alice has received a beautiful present from Bob. The present contains ...