首页 > 其他 > 详细

Increasing Sequence CodeForces - 11A

时间:2017-11-09 20:37:48      阅读:185      评论:0      收藏:0      [点我收藏+]

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

原文:http://www.cnblogs.com/hehe54321/p/cf-11a.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!