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 }
时间: 2024-11-13 09:48:27

Increasing Sequence CodeForces - 11A的相关文章

Codeforces 490E. Restoring Increasing Sequence 二分

统计有几个'?',然后二分检测取满足条件的最小的数就可以了. 注意没有问号的时候也要检测一下.... E. Restoring Increasing Sequence time limit per test 1 second memory limit per test 256 megabytes input standard input output standard output Peter wrote on the board a strictly increasing sequence o

cf 11A Increasing Sequence(水,)

题意: A sequence a0, a1, ..., at - 1 is called increasing if ai - 1 < ai for each i: 0 < i < t. You are given a sequence b0, b1, ..., bn - 1 and a positive integer d. In each move you may choose one element of the given sequence and add d to it. Wh

CodeForces 490E Restoring Increasing Sequence(贪心)

CodeForces 490E 题目大意:给N个正整数,然而这些正整数中间有些数字是被'?'遮挡住了,每个'?'可以还原回一个数字,希望给定的这N个整数形成一个递增的序列.可以的话,给出这N个整数的序列,不行返回N0. 解题思路:每个整数都在满足条件的情况下尽量的小,写了一个非递归版本的,发现要考虑的因素太多了,wa了太多遍.后面改成了递归版本的,但是这个比较耗时. 代码: #include <cstdio> #include <cstring> const int MAXL =

CodeForces 490E Restoring Increasing Sequence

题意: 一个严格递增序列  某些数字的某些位被盖住了  求  恢复后的序列 思路: 贪心  让每个数在大于前一个的基础上尽量的小 先讨论数字长度 len[i]<len[i-1] 一定是NO len[i]>len[i-1] 除了第一位如果是?就填1以外  其他?全填0 len[i]==len[i-1] dfs搜索num[i]格式下大于num[i-1]的最小的数 代码: #include<cstdio> #include<iostream> #include<cstr

Longest Increasing Sequence

1 public class Longest_Increasing_Subsequence { 2 /** 3 * O(N^2) 4 * DP 5 * 思路: 6 * 示例:[1,0,2,4,10,5] 7 * 找出以上数组的LIS的长度 8 * 分析: 9 * 只要求长度,并不要求找出具体的序列 10 * 问题可以拆分为 11 * 1. 对于[1],找出LIS 12 * 2. 对于[1,0],找出LIS 13 * 3. 对于[1,0,2],找出LIS 14 * 4. 对于[1,0,2,4],找

Codeforces Round #279 (Div. 2) ABCD

Codeforces Round #279 (Div. 2) 做得我都变绿了! Problems # Name     A Team Olympiad standard input/output 1 s, 256 MB  x2377 B Queue standard input/output 2 s, 256 MB  x1250 C Hacking Cypher standard input/output 1 s, 256 MB  x740 D Chocolate standard input/

Codeforces #550 (Div3) - G.Two Merged Sequences(dp / 贪心)

Problem  Codeforces #550 (Div3) - G.Two Merged Sequences Time Limit: 2000 mSec Problem Description Two integer sequences existed initially, one of them was strictly increasing, and another one — strictly decreasing. Strictly increasing sequence is a

Long Jumps CodeForces - 479D

E - Long Jumps CodeForces - 479D Valery is a PE teacher at a school in Berland. Soon the students are going to take a test in long jumps, and Valery has lost his favorite ruler! However, there is no reason for disappointment, as Valery has found anot

中南OJ1551: Longest Increasing Subsequence Again(分块+离散化线段树)

1551: Longest Increasing Subsequence Again Time Limit: 2 Sec  Memory Limit: 256 MB Submit: 29  Solved: 15 [Submit][Status][Web Board] Description Give you a numeric sequence. If you can demolish arbitrary amount of numbers, what is the length of the