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> ...
随机推荐
- shell系统检测->
系统状态检测脚本练习 1-> 查看磁盘状态 思路:查看磁盘/当前使用状态,如果使用率超过80%则报警发邮件 1.获取磁盘当前使用的值 df -h|grep /$ 2.从获取到的值中提取出,对应的 ...
- Java 并发--线程创建
随着处理器的多核化,为提高处理器的资源利用率应用程序的并发变应运而生了.现在的操作系统是多任务操作系统,多线程是实现多任务的一种方式. 进程是指一个内存中运行的应用程序,每个进程都有自己独立的内存空间 ...
- 分布式git
分布式 Git 你现在拥有了一个远程 Git 版本库,能为所有开发者共享代码提供服务,在一个本地工作流程下,你也已经熟悉 了基本 Git 命令.你现在可以学习如何利用 Git 提供的一些分布式工作流程 ...
- Python_oldboy_自动化运维之路_全栈考试(七)
1. 计算100-300之间所有能被3和7整除的所有数之和 # -*- coding: UTF-8 -*- #blog:http://www.cnblogs.com/linux-chenyang/ c ...
- (一)问候 HtmlUnit
第一节: HtmlUnit 简介 htmlunit 是一款开源的java 页面分析工具,读取页面后,可以有效的使用htmlunit分析页面上的内容.项目可以模拟浏览器运行,被誉为java浏览器的开源实 ...
- 一个文件系统过滤驱动的demo
因为没写过FSD过滤驱动,所以拿来练练手,没有什么技术含量.参考自Win内核安全与驱动开发. 先梳理一下大概的流程,就是怎么去绑定设备栈.怎么去过滤各种请求的. 首先肯定是要绑定设备栈的,来看下怎么绑 ...
- php-fpm进程管理方式(static和dynamic)
目前最新5.3.x的php-fpm,有两种管理进程的方式,分别是static和dynamic. 如果设置成static,进程数自始至终都是pm.max_children指定的数量,pm.start_s ...
- hdu 1398 整数划分变形 (母函数)
有1,4,9,16,25.....2^17这么多面值的硬币,问任意给定一个不大于300的正整数面额,用这些硬币来组成此面额总共有多少种组合种数 比如10全14 + 6个 14+4+1+19+1 求(1 ...
- Chrome-Adobe Flash 无法正常使用
https://support.google.com/chrome/answer/6258784 该网站因是是google.com,被强了,所以一般打不开. 故将google官方说明记录以下: 如果 ...
- 基于范围的for循环
语法: for ( for-range-declaration : expression ) statement 注意一般用auto表达类型.不需要修改时常用引用类型 例子: // range-bas ...