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. Field baseMapper in com.baomidou.mybatisplus.extension.service.impl.ServiceImpl required a single bean, but xx were found:

    在学习使用 mybatis-plus 时,遇到一个奇怪的异常 如 代码一: 代码一: Error starting ApplicationContext. To display the conditi ...

  2. Django、Flask、Tornado的区别?

    Django:Python 界最全能的 web 开发框架,battery-include 各种功能完备,可维护性和开发速度一级棒.常有人说 Django 慢,其实主要慢在 Django ORM 与数据 ...

  3. MY SQL数据库密码最简单的一个方法()

    https://zhidao.baidu.com/question/564368111.html 非常简单的一个修改方法!!!!!!!!!!!!!!!!!!!!! 最简单的方法就是借助第三方工具Nav ...

  4. Ajax&Json笔记

    ## 今日内容     1. AJAX:     2. JSON # AJAX:     1. 概念: ASynchronous JavaScript And XML    异步的JavaScript ...

  5. 美国Science公布:全球125个最前沿的科学难题(图)

    文章来源:https://www.toutiao.com/i6637224168045675021 美国Science在庆祝创刊125周年之际,公布了125个最具挑战性的科学问题.这些前沿科学和研究方 ...

  6. python添加清屏功能

    创建文件ClearWindow添加内容 class ClearWindow: menudefs = [ ('options', [None, ('Clear Shell Window', '<& ...

  7. vue2.0 之 生命周期

     一.vue1.x与vue2.x生命周期的变化区别及含义表(图表摘自网络)   二.vue2.x生命周期图和各阶段具体含义 beforecreated:el 和 data 并未初始化 created: ...

  8. 你真的懂git rebase吗?

    前段时间由于某种原因,开始接手开发公司前端Vue搭建的项目 该前端项目采用的是基于git rebase的形式去合并代码,而我之前使用git一直都是采用merge的形式合并分支代码,对于rebase一概 ...

  9. Thymeleaf 整理

    1.标准变量表达式: thymeleaf中的变量表达式使用${变量名}的方式获取其中的数据 th:text="" 是thymeleaf的一个属性,用于文本的显示 如:<spa ...

  10. larval 使用redis做缓存

    1.存redis 使用setex命令可以同时设置数据和保存时间 $data = [ 'name'=>zhangsan, 'age' => 28, 'sex' => 1 ]; Redi ...