Increasing Sequence CodeForces

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 }
原文地址:https://www.cnblogs.com/hehe54321/p/cf-11a.html