codeforce 606C - Sorting Railway Cars

题意:给你一串数,没个数只能往前提到首位,或则往后放末尾。问最少步骤使操作后的序列成上升序列。

思路:最长连续子序列。

 1 #include<iostream>
 2 #include<stdio.h>
 3 #include<stdlib.h>
 4 #include<memory.h>
 5 #include<string.h>
 6 #include<algorithm>
 7 #include<cmath>
 8 const int N = 30;
 9 const int inf=-100000;
10 using namespace std;
11
12 int main()
13 {
14     int n;
15     int h[100010];
16     int dp[100010];
17     int a[100010];
18     scanf("%d",&n);
19     for(int i=1; i<=n; i++)
20     {
21         scanf("%d",&a[i]);
22     }
23     int ans=0;
24     for(int i=1; i<=n; i++)
25     {
26         h[a[i]]++;
27         if(h[a[i]-1])
28             dp[a[i]]=dp[a[i]-1]+1;
29         else
30             dp[a[i]]=1;
31         ans=max(dp[a[i]],ans);
32     }
33     cout<<n-ans<<endl;
34     return 0;
35 }

时间: 2024-11-05 11:44:12

codeforce 606C - Sorting Railway Cars的相关文章

Codeforces Round #335 (Div. 2) C. Sorting Railway Cars 连续LIS

C. Sorting Railway Cars An infinitely long railway has a train consisting of n cars, numbered from 1 to n (the numbers of all the cars are distinct) and positioned in arbitrary order. David Blaine wants to sort the railway cars in the order of increa

Codeforces 605A. Sorting Railway Cars

An infinitely long railway has a train consisting of n cars, numbered from 1 to n (the numbers of all the cars are distinct) and positioned in arbitrary order. David Blaine wants to sort the railway cars in the order of increasing numbers. In one mov

CodeForces 605A Sorting Railway Cars 思维

早起一水…… 题意看着和蓝桥杯B组的大题第二道貌似一个意思…… 不过还是有亮瞎双眼的超短代码…… 总的意思呢…… 就是最长增长子序列且增长差距为1的的…… 然后n-最大长度…… 这都怎么想的…… 希望今天的省选可以亮光乍现~~~ 1 #include<stdio.h> 2 #include<iostream> 3 #include<string.h> 4 #include<algorithm> 5 #include<math.h> 6 using

codeforces 的20道C题

A - Warrior and Archer CodeForces - 595C n  偶数  然后n个数字 A B 轮流取一个 A让差变小B让差变大 直到最后2 个   求的是最小剩下的差 最后剩下的 L R  相距 n/2    求一下最小的就行 #include <iostream> #include <cstdio> #include <cmath> #include <map> #include <algorithm> #include

Codeforces Round #335 (Div. 2)

水 A - Magic Spheres 这题也卡了很久很久,关键是“至少”,所以只要判断多出来的是否比需要的多就行了. #include <bits/stdc++.h> using namespace std; #define lson l, mid, o << 1 #define rson mid + 1, r, o << 1 | 1 typedef long long ll; const int N = 1e5 + 5; const int INF = 0x3f3f

百度啊哈放假哈是否可拉伸交罚款了萨芬

http://www.ebay.com/cln/bya9700/cars/167373057012/2015.02.01 http://www.ebay.com/cln/w.ka053/cars/167170359019/2015.02.01 http://www.ebay.com/cln/y-we561/cars/167640056015/2015.02.01 http://www.ebay.com/cln/bin9178/cars/167511984011/2015.02.01 http:/

百度的附件是甲方可拉伸了开发

http://www.ebay.com/cln/yf25396/cars/167277998010/2015.02.09 http://www.ebay.com/cln/huan-con/cars/167393960016/2015.02.09 http://www.ebay.com/cln/rua-don/cars/167549052015/2015.02.09 http://www.ebay.com/cln/zal9627/cars/167278006010/2015.02.09 http:

百度公司福建海事局放好久开始减肥

http://www.ebay.com/cln/cancn-klq15s/cars/167085132019/2015_02_05 http://www.ebay.com/cln/f_f8966/cars/167553237015/2015_02_05 http://www.ebay.com/cln/yua-me2/cars/167398057016/2015_02_05 http://www.ebay.com/cln/fcn3271/cars/167085150019/2015_02_05 h

百度风格和环境和健康科技可理解了

http://www.ebay.com/cln/tan4617-pbiacili/cars/167536635011/2015-02-05 http://www.ebay.com/cln/kcn7473/cars/167666085015/2015-02-05 http://www.ebay.com/cln/waxia72/cars/167536647011/2015-02-05 http://www.ebay.com/cln/donwa90/cars/167666086015/2015-02-