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. CF和OF的区别

    进位标志CF和溢出标志OF的区别: 有符号数和无符号数只是认为的进行区分,计算机从来不区分有符号数和无符号数.对于运算的数来说,只要符合进位的情况,CF就置1.只要符合溢出的情况,OF就置1.但是后续 ...

  2. docker下部署kafka集群(多个broker+多个zookeeper)

    网上关于kafka集群的搭建,基本是单个broker和单个zookeeper,测试研究的意义不大.于是折腾了下,终于把正宗的Kafka集群搭建出来了,在折腾中遇到了很多坑,后续有时间再专门整理份搭建问 ...

  3. 08: mysql主从原理

    1.1 mysql主从同步   参考博客:https://www.cnblogs.com/kevingrace/p/6256603.html 1.mysql主从同步(复制)概念 1. 将Mysql某一 ...

  4. Python 入门之 推导式

    Python 入门之 推导式 推导式就是构建比较有规律的列表,生成器,字典等一种简便的方式 1.推导式 (1)列表推导式 : <1> 普通循环: [变量 for循环] print([i f ...

  5. Linux中的各种锁及其基本原理

    Linux中的各种锁及其基本原理 1.概述 通过本文将了解到如下内容: Linux系统的并行性特征 互斥和同步机制 Linux中常用锁的基本特性 互斥锁和条件变量 2.Linux的并行性特征 Linu ...

  6. Delphi7所使用的WinAPI大全(摘自VCL源码,一共1200个函数)

    经过我整理的,去掉了A和W的重复.虽然没写注释,但以后要一个一个研究.有这些WINAPI就够用了. kernel32 = 'kernel32.dll'; gdi32 = 'gdi32.dll'; us ...

  7. 使用 ref 和 out 传递数组注意事项

    1.与所有的 out参数一样,在使用数组类型的 out 参数前必须先为其赋值,即必须由被调用方为其赋值 示例 :在此例中,在调用方(Main 方法)中声明数组 theArray,并在 FillArra ...

  8. python基本语法学习

    前言: 1.python是解释型语言 2.尽量使用python3.2014年的时候python官方宣布2.7支持到2020年,以后不会再发行2.8版本,尽快把程序迁移到3.x版本 基本语法: 1.变量 ...

  9. ECMAScript(ES) 6 之 let 与 const

    ES6 新增加了两个重要的 JavaScript 关键字 :let  和 const 先说一下 const :它用于声明一个只读的常量,一旦声明,常量的值就不能改变. const servicePat ...

  10. Android数据库使用指南(上)

    前言Android上的数据库是sqlite,虽然这个数据库是轻量级的,但是储存的东西可不少,sqlite官方表示理论存储容量为140TB,目前应该没有那么大容量的手机,存储能力太强了. 关于如何使用S ...