Atcoder arc079 D Decrease (Contestant ver.) (逆推)
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
0
Sample Output 1
4
3 3 3 3
Sample Input 2
1
Sample Output 2
3
1 0 3
Sample Input 3
2
Sample Output 3
2
2 2
The operation will be performed twice: [2, 2] -> [0, 3] -> [1, 1].
Sample Input 4
3
Sample Output 4
7
27 0 0 0 0 0 0
Sample Input 5
1234567894848
Sample Output 5
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.) (逆推)的更多相关文章
- Atcoder At Beginner Contest 068 D - Decrease (Contestant ver.)
D - Decrease (Contestant ver.) Time limit : 2sec / Memory limit : 256MB Score : 600 points Problem S ...
- 【构造】AtCoder Regular Contest 079 D - Decrease (Contestant ver.)
从n个t变化到n个t-1,恰好要n步,并且其中每一步的max值都>=t,所以把50个49当成最终局面,从这里开始,根据输入的K计算初始局面即可. #include<cstdio> # ...
- Atcoder AtCoder Regular Contest 079 E - Decrease (Judge ver.)
E - Decrease (Judge ver.) Time limit : 2sec / Memory limit : 256MB Score : 600 points Problem Statem ...
- UVA116Unidirectional TSP(DP+逆推)
http://acm.hust.edu.cn/vjudge/problem/viewProblem.action?id=18206 题意:M*N的数阵,从左边一列到右边一列走过的数的和的最小.并输出路 ...
- HDU 5844 LCM Walk(数学逆推)
http://acm.hdu.edu.cn/showproblem.php?pid=5584 题意: 现在有坐标(x,y),设它们的最小公倍数为k,接下来可以移动到(x+k,y)或者(x,y+k).现 ...
- hdu 5063 操作逆推+mul每次要*2%(modo - 1)
http://acm.hdu.edu.cn/showproblem.php?pid=5063 只有50个询问,50个操作逆推回去即可,注意mul每次要*2%(modo - 1)因为是指数! #incl ...
- uva10537 dijkstra + 逆推
21:49:45 2015-03-09 传送 http://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8& ...
- hdu 3853 LOOPS (概率dp 逆推求期望)
题目链接 LOOPS Time Limit: 15000/5000 MS (Java/Others) Memory Limit: 125536/65536 K (Java/Others)Tota ...
- 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= ...
随机推荐
- Python内置函数compile
英文文档: compile(source, filename, mode, flags=0, dont_inherit=False, optimize=-1) Compile the source i ...
- Mybatis-学习笔记(5)动态SQL
1.Mybatis采用功能强大的基于ONGL的表达式来完成动态SQL. 2.ONGL常用的元素有: 1>if <if test="id != null "> an ...
- Linux Apache使用CGI
CGI(Common Gateway Interface,通用网关接口)是网络服务器可以将查询传递到专门的程序中并且在网页上显示结果的标准机制.Apache等服务器默认是支持CGI的,只需要修改一下配 ...
- 如何通过PHP将excel的数据导入MySQL中
在开发PHP程序时,很多时候我们会有将数据批量导入数据库的需求,如学生信息批量添加到数据库中,而事先用excel编排好,对excel实行操作,便是我们比较常用的选择方式. 在对excel的操作中,ph ...
- [LeetCode] 84. 柱状图中最大的矩形
题目链接 : https://leetcode-cn.com/problems/largest-rectangle-in-histogram/ 题目描述: 给定 n 个非负整数,用来表示柱状图中各个柱 ...
- 第八讲 shiro 整合 ssm
1.整合ssm并且实现用户登录和菜单权限 2.将shiro整合到ssm中 (1)添加shiro相关jar包 (2)在web.xml中添加shiro配置 <!-- 新增shiro配置 --> ...
- Solr7.2.1环境搭建和配置ik中文分词器
solr7.2.1环境搭建和配置ik中文分词器 安装环境:Jdk 1.8. windows 10 安装包准备: solr 各种版本集合下载:http://archive.apache.org/dist ...
- memset,内存初始化函数
# include <string.h> void *memset(void *s, int c, unsigned long n); 函数的功能是:将指针变量 s 所指向的前 n 字节的 ...
- 14.Linux-CentOS系统proc文件系统丢失
问题: 在强制卸载根目录下的磁盘,导致/proc文件系统丢失. 解决: 重启服务器重新生成.
- rsync服务实践
RSYNC数据备份 RSYNC=Remote Sync 远程同步 高效,一定要结合shell 官方网站:https://rsync.samba.org/ Author: Andrew Tr ...