Increasing Sequence CodeForces - 11A

很简单的贪心。由于不能减少元素,只能增加,过程只能是从左到右一个个看过去,看到一个小于等于左边的数的数就把它加到比左边大,并记录加的次数。

错误记录:

但是很容易错...以前错了4次..过几个月来再做还是不能1A...

比如下面这个有很明显错误的程序

 #include<cstdio>
int n,d,last,now,ans;
int main()
{
int i;
scanf("%d%d",&n,&d);
scanf("%d",&last);
for(i=;i<=n;i++)
{
scanf("%d",&now);
if(now<=last)
{
ans+=(last-now)/d+;
now+=d*ans;
}
last=now;
}
printf("%d",ans);
return ;
}

2333333

 #include<cstdio>
int n,d,last,now,ans;
int main()
{
int i,tans;
scanf("%d%d",&n,&d);
scanf("%d",&last);
for(i=;i<=n;i++)
{
scanf("%d",&now);
if(now<=last)
{
tans=(last-now)/d+;
ans+=tans;
now+=d*tans;
}
last=now;
}
printf("%d",ans);
return ;
}

Increasing Sequence CodeForces - 11A的更多相关文章

  1. Codeforces Beta Round #11 A. Increasing Sequence 贪心

    A. Increasing Sequence 题目连接: http://www.codeforces.com/contest/11/problem/A Description A sequence a ...

  2. Codeforces Round #279 (Div. 2) E. Restoring Increasing Sequence 二分

    E. Restoring Increasing Sequence time limit per test 1 second memory limit per test 256 megabytes in ...

  3. Almost Regular Bracket Sequence CodeForces - 1095E (线段树,单点更新,区间查询维护括号序列)

    Almost Regular Bracket Sequence CodeForces - 1095E You are given a bracket sequence ss consisting of ...

  4. cf 11A Increasing Sequence(水,)

    题意: A sequence a0, a1, ..., at - 1 is called increasing if ai - 1 < ai for each i: 0 < i <  ...

  5. Longest Increasing Sequence

    public class Longest_Increasing_Subsequence { /** * O(N^2) * DP * 思路: * 示例:[1,0,2,4,10,5] * 找出以上数组的L ...

  6. AC日记——The Child and Sequence codeforces 250D

    D - The Child and Sequence 思路: 因为有区间取模操作所以没法用标记下传: 我们发现,当一个数小于要取模的值时就可以放弃: 凭借这个来减少更新线段树的次数: 来,上代码: # ...

  7. C. Vasily the Bear and Sequence Codeforces 336C(枚举,思维)

    C. Vasily the Bear and Sequence time limit per test 1 second memory limit per test 256 megabytes inp ...

  8. Prefix Product Sequence CodeForces - 487C (数论,构造)

    大意: 构造一个[1,2,...n]的排列, 使得前缀积模n为[0,1,...,n-1]的排列 这种构造都好巧妙啊, 大概翻一下官方题解好了 对于所有>=6的合数$n$, 有$(n-1)! \e ...

  9. Almost Increasing Array CodeForces - 946G (dp)

    大意: 定义几乎递增序列为删除不超过一个数后序列严格递增. 给定序列, 求最少改变多少个数能变为几乎递增序列. 跟hdu5256类似,

随机推荐

  1. [教程]Delphi 中三种回调函数形式解析

    Delphi 支持三种形式的回调函数 全局函数这种方式几乎是所有的语言都支持的,类的静态函数也可以归为此类,它保存的只是一个函数的代码起始地址指针( Pointer ).在 Delphi 中声明一般为 ...

  2. Linux进程IPC浅析[进程间通信SystemV共享内存]

    Linux进程IPC浅析[进程间通信SystemV共享内存] 共享内存概念,概述 共享内存的相关函数 共享内存概念,概述: 共享内存区域是被多个进程共享的一部分物理内存 多个进程都可把该共享内存映射到 ...

  3. python3 base64模块代码分析

    #! /usr/bin/env python3 """Base16, Base32, Base64 (RFC 3548), Base85 and Ascii85 data ...

  4. Evaluate Reverse Polish Notation --leetcode

    原题链接:https://oj.leetcode.com/problems/evaluate-reverse-polish-notation/ 题目大意:给出逆波兰式,然后求其结果. 解题方法:单个栈 ...

  5. oracle连接串的一种写法

    我在.NET项目里访问oracle,向来是规规矩矩地这样写: DATA SOURCE=PDBGZFBC;PASSWORD=test;PERSIST SECURITY INFO=True;USER ID ...

  6. debian repository的成长过程

    1 基本概念 1.1 健康的安装 在端系统中的一次健康的安装指的是,在安装的包的集合中,所有的依赖都满足,并且没有冲突存在. 这的健康的安装是相对于端系统而言的,并不是相对于整个repo而言的.对整个 ...

  7. JDK各版本内容和新特性

    JDK各版本内容和新特性 - yanlzhl - 博客园 https://www.cnblogs.com/yanlzhl/articles/5694470.html    版本JDK1.0:1995年 ...

  8. Node.js 101(2): Promise and async

    --原文地址:http://blog.chrisyip.im/nodejs-101-package-promise-and-async 先回想一下 Sagase 的项目结构: lib/ cli.js ...

  9. bzoj3612: [Heoi2014]平衡

    首先不可重的整数规划是fi,j=fi-1,j-i+fi,j-i的 然后现在加了一个限制,分成的数不能超过n,那么对于拼大于n的数的时候多减一个fi-1,j-n-1 接下来是优化代码暴露我自带巨大常数的 ...

  10. UVA11183 Teen Girl Squad —— 最小树形图

    题目链接:https://vjudge.net/problem/UVA-11183 You are part of a group of n teenage girls armed with cell ...