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= ...
随机推荐
- (3.4)常用知识-char与varchar的选择
1.char与varchar的比较 (1)数据存储开销 [1]varchar列需要2个额外的字节来记录存储数据的长度 [2]每个可为null的char列,需要一些字节(空位图)来反应数据的为空性 [3 ...
- C++ cin相关函数总结
输入原理: 程序的输入都建有一个缓冲区,即输入缓冲区.一次输入过程是这样的,当一次键盘输入结束时会将输入的数据存入输入缓冲区,而cin函数直接从输入缓冲区中取数据.正因为cin函数是直接从缓冲区取数据 ...
- 初次尝试python爬虫,爬取小说网站的小说。
本次是小阿鹏,第一次通过python爬虫去爬一个小说网站的小说. 下面直接上菜. 1.首先我需要导入相应的包,这里我采用了第三方模块的架包,requests.requests是python实现的简单易 ...
- Vue框架前言
Vue框架 Vue 框架: 官网 vue框架:渐进式JavaScript框架 vue一个环境:可以只控制页面中一个标签.可以控制一组标签.可以控制整个页面.可以控制整个项目 vue可以根据实际需求,选 ...
- author认证模块
author认证模块 用auth模块 你就用全套 不是自己写一部分 用别人一部分 创建超级管理员,用于登录DJango admin的后台管理 命令:createsuperuser,输入顺序用户 ...
- gradle上sourceSets配置&同名文件合并问题
gradle的sourceSets可以对不同的buildType, productFlavor,buildVariant设置不同的文件路径,进行多样化处理. sourceSets{ main{ man ...
- deletefile 与KILL
1.Kill 语句 从磁盘中删除文件.语法Kill pathname必要的 pathname 参数是用来指定一个文件名的字符串表达式.pathname 可以包含目录或文件夹.以及驱动器.说明在 Mic ...
- qt配置opengl
cmake 编译opengl,参考https://wiki.qt.io/How_to_setup_Qt_and_openCV_on_Windows cmake configure完成没有错误后,点击g ...
- CPU指令重排序与MESI缓存一致性
一.重排序场景 class ResortDemo { int a = 0; boolean flag = false; public void writer() { a = 1; //1 flag = ...
- 你真的懂git rebase吗?
前段时间由于某种原因,开始接手开发公司前端Vue搭建的项目 该前端项目采用的是基于git rebase的形式去合并代码,而我之前使用git一直都是采用merge的形式合并分支代码,对于rebase一概 ...