Increasing Sequence CodeForces - 11A

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了Increasing Sequence CodeForces - 11A相关的知识,希望对你有一定的参考价值。

Increasing Sequence CodeForces - 11A

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

错误记录:

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

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

 1 #include<cstdio>
 2 int n,d,last,now,ans;
 3 int main()
 4 {
 5     int i;
 6     scanf("%d%d",&n,&d);
 7     scanf("%d",&last);
 8     for(i=2;i<=n;i++)
 9     {
10         scanf("%d",&now);
11         if(now<=last)
12         {
13             ans+=(last-now)/d+1;
14             now+=d*ans;
15         }
16         last=now;
17     }
18     printf("%d",ans);
19     return 0;
20 }
2333333
 1 #include<cstdio>
 2 int n,d,last,now,ans;
 3 int main()
 4 {
 5     int i,tans;
 6     scanf("%d%d",&n,&d);
 7     scanf("%d",&last);
 8     for(i=2;i<=n;i++)
 9     {
10         scanf("%d",&now);
11         if(now<=last)
12         {
13             tans=(last-now)/d+1;
14             ans+=tans;
15             now+=d*tans;
16         }
17         last=now;
18     }
19     printf("%d",ans);
20     return 0;
21 }

以上是关于Increasing Sequence CodeForces - 11A的主要内容,如果未能解决你的问题,请参考以下文章

Longest Increasing Subsequence

674. Longest Continuous Increasing Subsequence

Longest Increasing Subsequence

334. Increasing Triplet Subsequence

674. Longest Continuous Increasing Subsequence@python

903. Valid Permutations for DI Sequence