Increasing Sequence CodeForces - 11A
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的更多相关文章
- Codeforces Beta Round #11 A. Increasing Sequence 贪心
A. Increasing Sequence 题目连接: http://www.codeforces.com/contest/11/problem/A Description A sequence a ...
- 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 ...
- Almost Regular Bracket Sequence CodeForces - 1095E (线段树,单点更新,区间查询维护括号序列)
Almost Regular Bracket Sequence CodeForces - 1095E You are given a bracket sequence ss consisting of ...
- cf 11A Increasing Sequence(水,)
题意: A sequence a0, a1, ..., at - 1 is called increasing if ai - 1 < ai for each i: 0 < i < ...
- Longest Increasing Sequence
public class Longest_Increasing_Subsequence { /** * O(N^2) * DP * 思路: * 示例:[1,0,2,4,10,5] * 找出以上数组的L ...
- AC日记——The Child and Sequence codeforces 250D
D - The Child and Sequence 思路: 因为有区间取模操作所以没法用标记下传: 我们发现,当一个数小于要取模的值时就可以放弃: 凭借这个来减少更新线段树的次数: 来,上代码: # ...
- 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 ...
- Prefix Product Sequence CodeForces - 487C (数论,构造)
大意: 构造一个[1,2,...n]的排列, 使得前缀积模n为[0,1,...,n-1]的排列 这种构造都好巧妙啊, 大概翻一下官方题解好了 对于所有>=6的合数$n$, 有$(n-1)! \e ...
- Almost Increasing Array CodeForces - 946G (dp)
大意: 定义几乎递增序列为删除不超过一个数后序列严格递增. 给定序列, 求最少改变多少个数能变为几乎递增序列. 跟hdu5256类似,
随机推荐
- kvm虚拟化学习笔记(三)之windows kvm虚拟机安装
KVM虚拟化学习笔记系列文章列表----------------------------------------kvm虚拟化学习笔记(一)之kvm虚拟化环境安装http://koumm.blog.51 ...
- 【Todo】STAR面试法
今天在面试培训的时候,接触到了STAR面试法. 觉得挺好的,用来准备非技术面试,还蛮全面的.所以可以多了解一下. 可以参考:http://www.hrloo.com/rz/73652.html
- 常见Python运行时错误
1)忘记在 if , elif , else , for , while , class ,def 声明末尾添加 :(导致 “SyntaxError :invalid syntax”) 该错误将发生在 ...
- 汝佳大神的紫书上写错了?uva10048
算法竞赛入门经典第二版的365页例题11-5噪音.应该是"之和"换成"取最大值","取最小值"还是取最小值 假设我错了,请大家务必指点小弟 ...
- Qt移动应用开发(四):应用粒子特效
Qt移动应用开发(四):应用粒子特效 上一篇文章介绍了Qt Quick是如何对帧动画进行支持的.帧动画的实现离不开状态机.而状态机.动画和状态切换(transitions)则是Qt框架的核心内容.也就 ...
- 基于开源项目的在线网络视频直播项目---pc端的推流
https://github.com/winlinvip/simple-rtmp-server/issues/66 https://github.com/justinmakaila/iOS-Frame ...
- JAVA 并发编程-返回运行结果(Callable和Future)(九)
启动一个线程不论使用Thread或者Runnable的时候.都是没有返回结果的. 也就是说Thread和Runnable的run()方法必须没有返回值. public void run(){} 解决方 ...
- DataTabless Add rows
参考官网案例:https://datatables.net/examples/api/add_row.html JS: $(document).ready(function() { var t ...
- (21) java web的struts2框架的使用-Action实现的三种方式
上一篇介绍了struts使用的四个步骤. 其中在开发action的时候,可以有三种实现方式: 1,写一个类,继承与ActionSupport 2,写一个类,实现Action接口 3,写一个类,实现业务 ...
- Lightoj 1006 Hex-a-bonacci
Given a code (not optimized), and necessary inputs, you have to find the output of the code for the ...