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类似,
随机推荐
- the attribute buffer size is too small 解决方法
在进行查询的时候引发The attribute buffer size is too small错误解决 http://bbs.esrichina-bj.cn/esri/viewthread.php? ...
- 切勿创建包括auto_ptr的容器对象
当你拷贝一个auto_ptr时,它所指向的对象的全部权被移交到拷入的auto_ptr上,而它自身被置为NULL.我的理解是:拷贝一个auto_ptr意味着改变它的值.比如: auto_ptr&l ...
- Android项目之HomeHealth基础学习2:Service
一. Service简单介绍 Service是android 系统中的四大组件之中的一个(Activity.Service.BroadcastReceiver.ContentProvider),它跟A ...
- STL vector的介绍(1)
尝试下翻译STL里面的一些easy和算法.四级过了.六级刚考.顺便练练自己的英语水平.翻译的不好的地方请大神多多不吝赐教哈.方便我改正. 原来均来自:http://www.cplusplus.com/ ...
- ReLu(修正线性单元)、sigmoid和tahh的比较
不多说,直接上干货! 最近,在看论文,提及到这个修正线性单元(Rectified linear unit,ReLU). Deep Sparse Rectifier Neural Networks Re ...
- STL_算法_最小值和最大值(min_element、max_element)
C++ Primer 学习中... 简单记录下我的学习过程 (代码为主) min_element.max_element 找最小.最大值. 非常easy没什么大作用 #include<iost ...
- 跨域,Content-Type组件
1,跨域:是浏览器的同源策略 阻止ajax请求不组织src请求 2,一个源的定义:如果两个页面的协议,端口(如果由指定)和域名都相同,则两个页面具有相同的源 下面给出相对http://a.xyz.co ...
- 8核 16g 及时释放内存空间
del 释放 大变量 所在内存空间 GB数据
- 关于前端js拼接字符串的一点小经验
1.今天在做项目的时候遇到一个问题,就是使用onclick="xxx()" 点击事件的时候,参数如果为全数字就会出现点击无反应的问题.但是当参数为字符串或者动态内容的时候就会出现 ...
- mysql08---优化01
Mysql数据库的优化技术 对mysql优化时一个综合性的技术,主要包括 a: 表的设计合理化(符合3NF) b: 添加适当索引(index) [四种: 普通索引(什么都不写).主键索引(有一个主键 ...