D - Decrease (Contestant ver.)


Time limit : 2sec / Memory limit : 256MB

Score : 600 points

Problem Statement

We have a sequence of length N consisting of non-negative integers. Consider performing the following operation on this sequence until the largest element in this sequence becomes N−1 or smaller.

  • Determine the largest element in the sequence (if there is more than one, choose one). Decrease the value of this element by N, and increase each of the other elements by 1.

It can be proved that the largest element in the sequence becomes N−1 or smaller after a finite number of operations.

You are given an integer K. Find an integer sequence ai such that the number of times we will perform the above operation is exactly K. It can be shown that there is always such a sequence under the constraints on input and output in this problem.

Constraints

  • 0≤K≤50×1016

Input

Input is given from Standard Input in the following format:

K

Output

Print a solution in the following format:

N
a1 a2 ... aN

Here, 2≤N≤50 and 0≤ai≤1016+1000 must hold.


Sample Input 1

Copy
0

Sample Output 1

Copy
4
3 3 3 3

Sample Input 2

Copy
1

Sample Output 2

Copy
3
1 0 3

Sample Input 3

Copy
2

Sample Output 3

Copy
2
2 2

The operation will be performed twice: [2, 2] -> [0, 3] -> [1, 1].


Sample Input 4

Copy
3

Sample Output 4

Copy
7
27 0 0 0 0 0 0

Sample Input 5

Copy
1234567894848

Sample Output 5

Copy
10
1000 193 256 777 0 1 1192 1234567891011 48 425

题意:

  要你输出一个长度为N数组,满足k次操作。每一次操作选择数组里面最大的一个,将这个数减去N,其他的数全部加1。当执行完k次操作后,数组里面的最大一个数要小于等于N-1。这k次操作中全部数都要大于等于0.(k <= 50* 1016 , N<=50)

题解:

  我们知道在最后的时候最大的是N-1。那么我们可以构造一个[0, 49] 的N为50 的数组。

  你每次选择一个最小的数加50, 其他是数减1。很明显这个[0, 49] 的数组是符合的。

  当你执行了50次操作的时候,你会发现数组变成了[1, 50]。

  我们就可以 在[0, 49] 的数组上直接 加上 循环次数 ((k-1/50)+1) - 1。

  我们还剩下 k%N 次操作

  如果当k%N > 0 的时候,直接暴力这些操作,选择一个最小的数+N, 其他数--。

  如果k%N == 0。 因为是N的倍数,因为循环次数是算的向下完整的循环,k%N==0,会使全部数+1.

  (k = 50)   [0, 49] 上加上了 49/50+1-1 = 0;但是第50次就变成了[1, 50]。

  

 #include <iostream>
#include <cstdio>
#include <cstring>
#include <string>
#include <algorithm>
#include <cmath>
#include <vector>
#include <queue>
#include <map>
#include <stack>
#include <set>
using namespace std;
typedef long long LL;
typedef unsigned long long uLL;
#define ms(a, b) memset(a, b, sizeof(a))
#define pb push_back
#define mp make_pair
#define eps 0.0000000001
#define IOS ios::sync_with_stdio(0);cin.tie(0);
const LL INF = 0x3f3f3f3f3f3f3f3f;
const int inf = 0x3f3f3f3f;
const int mod = 1e9+;
const int maxn = +;
LL a[];
int main() {
#ifdef LOCAL
freopen("input.txt", "r", stdin);
// freopen("output.txt", "w", stdout);
#endif
// IOS
LL k;scanf("%lld", &k);
if(k==) cout << "2\n1 1\n";
else{
int N = ;
LL t = (k-)/N + ;
for(int i = ;i<=N;i++) a[i] = i-;
for(int i = ;i<=N;i++) a[i] += (t-);
int hh = k%N;
if(hh==){
for(int i = ;i<=N;i++) a[i]++;
}
for(int i = ;i<=hh;i++){
for(int j = ;j<=N;j++){
if(i==j) a[i] += N;
else a[j]--;
}
}
printf("%d\n", N);
for(int i = ;i<=N;i++)
printf("%lld ", a[i]);
printf("\n");
}
return ;
}

  

Atcoder arc079 D Decrease (Contestant ver.) (逆推)的更多相关文章

  1. Atcoder At Beginner Contest 068 D - Decrease (Contestant ver.)

    D - Decrease (Contestant ver.) Time limit : 2sec / Memory limit : 256MB Score : 600 points Problem S ...

  2. 【构造】AtCoder Regular Contest 079 D - Decrease (Contestant ver.)

    从n个t变化到n个t-1,恰好要n步,并且其中每一步的max值都>=t,所以把50个49当成最终局面,从这里开始,根据输入的K计算初始局面即可. #include<cstdio> # ...

  3. Atcoder AtCoder Regular Contest 079 E - Decrease (Judge ver.)

    E - Decrease (Judge ver.) Time limit : 2sec / Memory limit : 256MB Score : 600 points Problem Statem ...

  4. UVA116Unidirectional TSP(DP+逆推)

    http://acm.hust.edu.cn/vjudge/problem/viewProblem.action?id=18206 题意:M*N的数阵,从左边一列到右边一列走过的数的和的最小.并输出路 ...

  5. HDU 5844 LCM Walk(数学逆推)

    http://acm.hdu.edu.cn/showproblem.php?pid=5584 题意: 现在有坐标(x,y),设它们的最小公倍数为k,接下来可以移动到(x+k,y)或者(x,y+k).现 ...

  6. hdu 5063 操作逆推+mul每次要*2%(modo - 1)

    http://acm.hdu.edu.cn/showproblem.php?pid=5063 只有50个询问,50个操作逆推回去即可,注意mul每次要*2%(modo - 1)因为是指数! #incl ...

  7. uva10537 dijkstra + 逆推

    21:49:45 2015-03-09 传送 http://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8& ...

  8. hdu 3853 LOOPS (概率dp 逆推求期望)

    题目链接 LOOPS Time Limit: 15000/5000 MS (Java/Others)    Memory Limit: 125536/65536 K (Java/Others)Tota ...

  9. UVA 10537 Toll! Revisited (逆推,最短路)

    从终点逆推,d[u]表示进入u以后剩下的货物,那么进入u之前的货物数量设为y,d[u] = x,那么y-x=ceil(y/20.0)=(y-1)/20+1=(y+19)/20. (y-x)*20+r= ...

随机推荐

  1. Mybatis-学习笔记(7)缓存机制

    1.一级缓存 SqlSession级别的缓存,使用HashMap存储缓存数据,不同的SqlSession之间的缓存数据区域(HashMap)互不影响. 一级缓存的作用域是SqlSession范围(强调 ...

  2. Java数据结构之递归(Recursion)

    1. 递归解决问题 各种数学问题如:8皇后问题,汉诺塔,阶乘问题,迷宫问题,球和篮子的问题(google编程大赛) 各种算法中也会使用到递归,比如快速排序,归并排序,二分查找,分治算法等 将用栈解决的 ...

  3. java中Map的put函数和get函数用法

    ---内容开始--- 没有比较完整的说明他们的用法,一般就只能看源函数,但是看起来比较的费劲. 那么究竟put函数和get函数的用法是如何的呢? 当然java中的Map集合是有Key和Value的. ...

  4. Hyper-V Centos7 虚拟机固定IP

    在网上看到很多篇文章,自己也去试验过,结果实现的效果都不是很理想,并不是自己所需要的,下面是我自己研究,最后成功的经验,希望能够帮到大家.少走一些弯路. 需求 1.无论物理机的网络环境怎么变化,都需要 ...

  5. [LeetCode] 212. 单词搜索 II

    题目链接:https://leetcode-cn.com/problems/word-search-ii/ 题目描述: 给定一个二维网格 board 和一个字典中的单词列表 words,找出所有同时在 ...

  6. Excel如何通过关键字模糊匹配查找全称

    打开excel,以其素材为例,通过关键字模糊匹配查找全称.   在公司名下输入公式:=LOOKUP(1,0/FIND(D2,A2:A5),A2:A5),按回车键确定即可.   FIND(D2,A2:A ...

  7. mysqldump: [Warning] Using a password on the command line interface can be insecure.

    MySQL 5.6 警告信息 command line interface can be insecure 修复 在命令行输入密码,就会提示这些安全警告信息. Warning: Using a pas ...

  8. 如何让css隐藏滚动条 兼容谷歌、火狐、IE等各个浏览器

    项目中,页面效果需要展示一个页面的移动端效果,使用的是一个苹果手机样式背景图,咋也没用过苹果,咋也不敢形容. 如下图所示: 在谷歌浏览器如图一滚动条顺利隐藏,但是火狐就如图二了,有了滚动条丑的一批. ...

  9. idea解除版本控制

    解除版本控制删除两个文件: 1.idea中删除vcs.xml 2.在项目文件夹中删除.git 参考:https://blog.csdn.net/qq_37999340/article/details/ ...

  10. editplus的使用技巧

    数据库sql语句中的 in 后面需要 ('xx','bb')这样的结果,多的话修改起来就比较麻烦,这时候使用editplus 的替换功能就可以实现 ,顶部菜单的 搜索 - > 替换 或者 ctr ...