Codeforces Beta Round #11 A. Increasing Sequence

题目链接:http://www.codeforces.com/contest/11/problem/A


题意:给你一个序列,每次可以使一个元素加d,问最少加几次可以使得这个序列成为单调递增的序列


思路:直接从头向后扫,遇到需要加的就直接加就好了。



ac代码:

#include<stdio.h>
#include<math.h>
#include<string.h>
#include<stack>
#include<set>
#include<queue>
#include<vector>
#include<iostream>
#include<algorithm>
#define MAXN 1010000
#define LL long long
#define ll __int64
#define INF 0xfffffff
#define mem(x) memset(x,0,sizeof(x))
#define PI acos(-1)
#define eps 1e-8
using namespace std;
ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}
ll lcm(ll a,ll b){return a/gcd(a,b)*b;}
ll powmod(ll a,ll b,ll MOD){ll ans=1;while(b){if(b%2)ans=ans*a%MOD;a=a*a%MOD;b/=2;}return ans;}
double dpow(double a,ll b){double ans=1.0;while(b){if(b%2)ans=ans*a;a=a*a;b/=2;}return ans;}
//head
int a[2333];
int main()
{
    int n,i,j,d;
    while(scanf("%d%d",&n,&d)!=EOF)
    {
        for(i=1;i<=n;i++)
            scanf("%d",&a[i]);
        int ans=0;
        for(i=2;i<=n;i++)
        {
            if(a[i]<=a[i-1])
            {
                int k=(a[i-1]-a[i])/d+1;
                a[i]+=d*k;
                ans+=k;
            }
        }
        printf("%d\n",ans);
    }
    return 0;
}



你可能感兴趣的:(Codeforces Beta Round #11 A. Increasing Sequence)