11AIncreasing Sequence
来源:互联网 发布:用mac输入英文破折号 编辑:程序博客网 时间:2024/06/05 17:00
模拟+小技巧
题意给你一个长度小于等于2000的序列,你可以给任何一个元素加上不限次数给定的d值,让b序列变成严格的递增序列。如果单纯暴力,b[n-1]<=b[i]时,就给b[i]+=d就会超时。所以我们需要定义一个x保存他们的差值,因为当前差值可能不是d的倍数,不能直接把x家在b[i]上,所以看看能加几个整数倍的d,最后再来暴力,30ms过。
A. Increasing Sequence time limit per test1 second memory limit per test64 megabytes inputstandard input outputstandard output
A sequence a0, a1, …, at - 1 is called increasing if ai - 1 < ai for each i: 0 < i < t.
You are given a sequence b0, b1, …, bn - 1 and a positive integer d. In each move you may choose one element of the given sequence and add d to it. What is the least number of moves required to make the given sequence increasing?
Input
The first line of the input contains two integer numbers n and d (2 ≤ n ≤ 2000, 1 ≤ d ≤ 106). The second line contains space separated sequence b0, b1, …, bn - 1 (1 ≤ bi ≤ 106).
Output
Output the minimal number of moves needed to make the sequence increasing.
Examples
input
4 2
1 3 3 2
output
3
#include<cstdio>#include<iostream>#include<algorithm>using namespace std;int main(){ int n,d,ans; int b[2010]; while(cin>>n>>d) { ans=0; for(int i=0; i<n; i++) { cin>>b[i]; if(i>=1&&b[i]<=b[i-1]) { int x=b[i-1]-b[i]; b[i]+=x/d*d; ans+=x/d; while(b[i]<=b[i-1]) { b[i]+=d; ans++; } } } cout<<ans<<endl; } return 0;}
- 11AIncreasing Sequence
- 11A - Increasing Sequence
- sequence
- SEQUENCE
- Sequence
- sequence
- sequence
- Sequence
- sequence
- sequence
- sequence
- Sequence
- Sequence
- Sequence
- Sequence
- sequence
- sequence
- sequence
- 杭电2017新生赛1007-找方块
- 动态数据结构
- gRPC 在 Python中的应用
- hibernate_day03_09_多对多操作
- C语言——Linux项目:文件复制命令的实现
- 11AIncreasing Sequence
- 随便写点关于我的github仓库
- 6.7 接口参数
- 超大背包问题 (折半枚举)
- uml类图与代码
- BigDecimal、DecimalFormat工具类-浮点类型计算格式化-史上最全=_=
- java日常学习:事件(简要版)
- application使用@符合问题:'@' that cannot start any token. (Do not use @ for indentation)
- 修复TortoiseGit文件夹和文件图标不显示