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. 【effective c++】模板与泛型编程

    模板元编程:在c++编译器内执行并于编译完成时停止执行 1.了解隐式接口和编译期多态 面向对象编程总是以显式接口(由函数名称.参数类型和返回类型构成)和运行期多态(虚函数)解决问题 模板及泛型编程:对 ...

  2. c++之函数对象、bind函数

    函数对象实质上是一个实现了operator()--括号操作符--的类. class Add { public: int operator()(int a, int b) { return a + b; ...

  3. Spark SQL数据载入和保存实战

    一:前置知识具体解释: Spark SQL重要是操作DataFrame,DataFrame本身提供了save和load的操作. Load:能够创建DataFrame. Save:把DataFrame中 ...

  4. Hadoop架构设计、执行原理具体解释

    1.Map-Reduce的逻辑过程 如果我们须要处理一批有关天气的数据.其格式例如以下: 依照ASCII码存储.每行一条记录 每一行字符从0開始计数,第15个到第18个字符为年 第25个到第29个字符 ...

  5. Java第二次作业參考代码

    Java第二次作业參考代码 [程序11] 题目:有1.2.3.4四个数字,能组成多少个互不同样且无反复数字的三位数?都是多少? public class lianxi11 { public stati ...

  6. mysql手记

    myisam innoDB是mysql经常使用的存储引擎 MyISAM不支持事务.也不支持外键.但其訪问速度快.对事务完整性没有要求. InnoDB存储引擎提供了具有提交.回滚和崩溃恢复能力的事务安全 ...

  7. MySQL基础笔记(三) 复杂查询

    所谓复杂查询,指涉及多个表.具有嵌套等复杂结构的查询.这里简要介绍典型的几种复杂查询格式. 一.连接查询 连接是区别关系与非关系系统的最重要的标志.通过连接运算符可以实现多个表查询.连接查询主要包括内 ...

  8. 比 git log 更强大的 git reflog

    最近做了个骚操作 git checkout commitId 修改了部分内容 git add . git commit -m '修改了些东西'   -> 此时git 会自动生成一个新的 comm ...

  9. elasticsearch_初始篇

    一.elasticsearch简单介绍 Elasticsearch 是一个基于Lucene的分布式.可扩展.近实时的搜索与数据分析引擎. 它能从项目一开始就赋予你的数据以搜索.分析和探索的能力. 实时 ...

  10. JDBC+XML+DOM4J

    利用xml文件封装数据库配置信息xml文件放在src目录下/testjdbc1/src/DBUtil.xml <?xml version="1.0" encoding=&qu ...