Codeforces 1240B. Sequence Sorting】的更多相关文章

传送门 分析题目发现如果把某个数 $x$ 往左移,那么之后所有小于 $x$ 的数也都要往左移 如果把 $x$ 往右移,那么之后所有大于 $x$ 的数也都要往右移 考虑我们首先一定有一个操作 $n$ 次的合法方案 但是发现其实有些数可以不用操作,只要把比它小的和比它大的搞成合法就行了 发现其实不用操作的数的排名一定是连续的一段,证明可以这样考虑 假设排名不是连续的一段,那么两段中间一定有一个数 $x$ 要操作,那么所有大于 $x$ 数或者小于 $x$ 的数一定要操作 那么矛盾,证明完成 那么现在只…
D. Sequence Sorting 题目大意:给你一个序列,有一种操作就是对所有相同的数可以挪到最前面,也可以挪到最后面,问最少操作次数. 首先,对于很多个相同的数,可以缩成两个位置,一个是就是这个数出现的区间,一个是最大位置,一个是最小位置. 如果数不挪,那就必须是连续递增的一段数,而且这个些数不能相互影响,也就是小的那个数的最大位置一定要在大的那个数的最小位置的前面. 然后就是找最长的一段连续递增的序列了,这个序列有两个要求,一个是递增,一个是必须连续,意思是对于si 和si+1 不存在…
链接: https://codeforces.com/contest/1241/problem/D 题意: You are given a sequence a1,a2,-,an, consisting of integers. You can apply the following operation to this sequence: choose some integer x and move all elements equal to x either to the beginning,…
http://codeforces.com/contest/876/problem/D D. Sorting the Coins time limit per test 1 second memory limit per test 512 megabytes input standard input output standard output Recently, Dima met with Sasha in a philatelic store, and since then they are…
C. Sorting Railway Cars time limit per test 2 seconds memory limit per test 256 megabytes input standard input output standard output An infinitely long railway has a train consisting of n cars, numbered from 1 to n (the numbers of all the cars are d…
B. Cards Sorting time limit per test 1 second memory limit per test 256 megabytes input standard input output standard output Vasily has a deck of cards consisting of n cards. There is an integer on each of the cards, this integer is between 1 and 10…
题目链接: http://www.codeforces.com/contest/606/problem/C 一道dp问题,我们可以考虑什么情况下移动,才能移动最少.很明显,除去需要移动的车,剩下的车,一定是相差为1的递增序列,而且这个序列一定也是最长的,例如4 1 2 5 3, 4 5是需要移动的,不移动的序列是1 2 3,所以我们只要求出这一最长的递增序列,用n去减就可以了. dp[i]是以i为结尾,最长的递增序列,所以dp[i] = dp[i-1]+1,求最大即为所求结果. #include…
题目链接:http://codeforces.com/problemset/problem/327/B 这道题目虽然超级简单,但是当初我还真的没有想出来做法,囧,看完别人的代码恍然大悟. #include <cstdio> #include <cstdlib> #include <cmath> int main(void) { int n; scanf("%d", &n); ; i <= n+n; ++i) { printf("…
http://codeforces.com/contest/13/problem/C 题目大意 给定一个含有N个数的序列,要求你对一些数减掉或者加上某个值,使得序列变为非递减的,问你加减的值的总和最少是多少? 思路:所有数最终构成的集合一定是一开始所有数构成数的集合的子集,因此dp[i][j]代表当前第i个数,递增序列在第j个数的代价. #include<cstdio> #include<cstring> #include<cmath> #include<iost…
B. Hungry Sequence time limit per test 1 second memory limit per test 256 megabytes input standard input output standard output Iahub and Iahubina went to a date at a luxury restaurant. Everything went fine until paying for the food. Instead of money…