Codeforces Beta Round #11 A. Increasing Sequence 贪心
A. Increasing Sequence
题目连接:
http://www.codeforces.com/contest/11/problem/A
Description
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.
Sample Input
4 2
1 3 3 2
Sample Output
3
Hint
题意
你每次操作可以使得一个数增加d,问你最小操作多少次,可以使得这个序列变成一个递增序列
题解:
贪心就好了,能变就变,不用变的时候不变就好了
代码
#include<bits/stdc++.h>
using namespace std;
const int maxn = 2005;
int a[maxn];
int main()
{
int n,d;
scanf("%d%d",&n,&d);
for(int i=1;i<=n;i++)scanf("%d",&a[i]);
long long ans = 0;
for(int i=2;i<=n;i++)if(a[i]<=a[i-1])
{
int tmp = (a[i-1]-a[i]+d)/d;
a[i]+=tmp*d;
ans+=tmp;
}
cout<<ans<<endl;
}
Codeforces Beta Round #11 A. Increasing Sequence 贪心的更多相关文章
- Codeforces Beta Round #11 B. Jumping Jack 数学
B. Jumping Jack 题目连接: http://www.codeforces.com/contest/11/problem/B Description Jack is working on ...
- 状压dp找寻环的个数 Codeforces Beta Round #11 D
http://codeforces.com/problemset/problem/11/D 题目大意:给你n个点,m条边,找该图中有几个换 思路:定义dp[i][j]表示i是圈的集合,j表示该集合的终 ...
- Codeforces Global Round 11 B. Chess Cheater (贪心,结构体排序)
题意:你和朋友进行了\(n\)个回合的棋艺切磋,没有平局,每次要么输要么赢,每次赢可以得一分,假如前一局也赢了,那么可以得两分,结果已成定局,但是你确可以作弊,最多修改\(k\)个回合的结果,问你作弊 ...
- 贪心+stack Codeforces Beta Round #5 C. Longest Regular Bracket Sequence
题目传送门 /* 题意:求最长括号匹配的长度和它的个数 贪心+stack:用栈存放最近的左括号的位置,若是有右括号匹配,则记录它们的长度,更新最大值,可以在O (n)解决 详细解释:http://bl ...
- Codeforces Beta Round #13 C. Sequence (DP)
题目大意 给一个数列,长度不超过 5000,每次可以将其中的一个数加 1 或者减 1,问,最少需要多少次操作,才能使得这个数列单调不降 数列中每个数为 -109-109 中的一个数 做法分析 先这样考 ...
- Codeforces Beta Round #80 (Div. 2 Only)【ABCD】
Codeforces Beta Round #80 (Div. 2 Only) A Blackjack1 题意 一共52张扑克,A代表1或者11,2-10表示自己的数字,其他都表示10 现在你已经有一 ...
- Codeforces Beta Round #79 (Div. 2 Only)
Codeforces Beta Round #79 (Div. 2 Only) http://codeforces.com/contest/102 A #include<bits/stdc++. ...
- Codeforces Beta Round #76 (Div. 2 Only)
Codeforces Beta Round #76 (Div. 2 Only) http://codeforces.com/contest/94 A #include<bits/stdc++.h ...
- Codeforces Beta Round #55 (Div. 2)
Codeforces Beta Round #55 (Div. 2) http://codeforces.com/contest/59 A #include<bits/stdc++.h> ...
随机推荐
- Ubuntu下 git 服务器的搭建【转】
转自:http://www.open-open.com/lib/view/open1391477731082.html 搭建git服务器的4个步骤 1 配置服务器前的准备工作 首先ubuntu系统 ...
- LINUX的DNS设置【转】
网卡DNS设置 用windos系统大家都知道,本地连接里面有一个DNS设置. 那么这个选项对应Linux系统的话就是在网卡配置文件,通过编辑vi /etc/sysconfig/network-scr ...
- MySQL数据记录大小写敏感问题【转】
MySQL大小写敏感 字符串大小写敏感和Mysql的数据库的名字.表名字.字段名字.还有字段值有关. 1.和数据库名字.表名字.存储过程和触发器有关 为0时:表示区分大小写,使用CREATE TABL ...
- Linux 网络编程实例
/*socket->bind->listen->accept->recv/recvfrom->send/sendto->close 客户端:socket->c ...
- iframe框架加载完成后执行函数
var iframe = document.createElement("iframe"); iframe.src = "http://www.baidu.com/&qu ...
- Linux学习笔记:rm删除文件和文件夹
使用rm命令删除一个文件或者目录 使用rmdir可以删除空文件夹 参数: -i:删除前逐一询问确认 -f:即使原档案属性设为唯读,亦直接删除,无需逐一确认 -r:递归 删除文件可以直接使用rm命令,若 ...
- U盘删除文件时提示“文件或目录损坏且无法读取”的解决方法
U盘删除文件时提示“文件或目录损坏且无法读取”的解决方法 出现原因:在写入或读取文件时,进行复制操作,此时复制到的文件是不完整的!或者移动硬盘/U盘中途被拔出,导致文件损坏 异常现象:被删文件(夹)属 ...
- Struts DispatchAction Example
The DispatchAction class (org.apache.struts.actions.DispatchAction) provides a way to group all rela ...
- DDR3调试记录
FPGA采集视频数据并写到DDR3,然后从DDR3读出并送给显示终端显示.不能稳定显示.但用FPGA内部逻辑产生color bar写到DDR3后读出来显示正常.因此DDR3部分逻辑没有问题 ...
- 有关FPGA
在FPGA发展历史上,前后共有过超过50家厂商,在国外目前剩下不到10家,除赛灵思和ALTERA两家持续不断地军备竞赛,其它的都有着各自固守的市场定位.即使是有新进入者,例如受英特尔新工艺支 ...