其实就是求总长度 - 一个最长“连续”自序列的长度 最长“连续”自序列即一个最长的lis,并且这个lis的值刚好是连续的,比如4,5,6... 遍历一遍,贪心就是了 遍历到第i个时,此时值为a[i],如果a[i]-1在前面已经出现过了,则len[a[i]] = len[a[i-1]]+1 否则len[a[i]] = 1 #include <cstdio> #include <algorithm> #include <cstring> #include <iostr…
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 dist…
早起一水…… 题意看着和蓝桥杯B组的大题第二道貌似一个意思…… 不过还是有亮瞎双眼的超短代码…… 总的意思呢…… 就是最长增长子序列且增长差距为1的的…… 然后n-最大长度…… 这都怎么想的…… 希望今天的省选可以亮光乍现~~~ #include<stdio.h> #include<iostream> #include<string.h> #include<algorithm> #include<math.h> using namespace s…
求一下最长数字连续上升的子序列长度,n-长度就是答案 O(n)可以出解,dp[i]=dp[i-1]+1,然后找到dp数组最大的值. #include<cstdio> #include<cstring> #include<cmath> #include<algorithm> using namespace std; const int INF=0x7FFFFFFF; +; int dp[maxn]; int n,x; int main() { while(~s…
C - Sorting Railway Cars   Time Limit:2000MS     Memory Limit:262144KB     64bit IO Format:%I64d & %I64u   CodeForces 606C Description An infinitely long railway has a train consisting of n cars, numbered from 1 to n (the numbers of all the cars are…
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 incr…
C. Sorting Railway Cars Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://www.codeforces.com/contest/606/problem/C Description An infinitely long railway has a train consisting of n cars, numbered from 1 to n (the numbers of all the cars are distin…
A. 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…
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…
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…
http://acm.hust.edu.cn/vjudge/contest/view.action?cid=102419#problem/E Description 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 B…
Description 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…
题目描述 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 on…
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 distinct) and positioned…
Description 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…
传送门 简单题 #include<bits/stdc++.h> using namespace std; struct node { double dan,weight; }a[]; bool cmp(node x,node y) { return x.dan<y.dan; } void init() { ;i<;i++) { a[i].dan=0.0;a[i].weight=0.0; } } int main() { int c; while(~scanf("%d&qu…
New Year is coming, and Jaehyun decided to read many books during 2015, unlike this year. He has n books numbered by integers from 1 to n. The weight of the i-th (1 ≤ i ≤ n) book is wi. As Jaehyun's house is not large enough to have a bookshelf, he k…
题目链接:http://codeforces.com/contest/605/problem/A 大意是对一个排列进行排序,每一次操作可以将一个数字从原来位置抽出放到开头或结尾,问最少需要操作多少次可以将原排列变为有序. 一个比较很想当然的算法是用长度减去最长上升子序列,但这是错误的. 反例: 5 1 3 4 5 2 按照n-lis,会得出答案1,但显然这是做不到的,答案应是2 正解应当是考虑最终变为有序时,所有未经操作的数字,应当是连续的.所以要使得操作次数最少就要求在原来数列中位置递增的最长…
LINK 题意:给出1~n数字的排列,求变为递增有序的最小交换次数 思路:水题.数据给的很小怎么搞都可以.由于坐标和数字都是1~n,所以我使用置换群求循环节个数和长度的方法. /** @Date : 2017-07-20 14:45:30 * @FileName: LightOJ 1166 贪心 或 置换群 水题.cpp * @Platform: Windows * @Author : Lweleth (SoungEarlf@gmail.com) * @Link : https://github…
一个男孩有n只玩具蜘蛛,每只蜘蛛都是一个树的结构,现在男孩准备把这n只小蜘蛛通过粘贴节点接在一起,形成一只大的蜘蛛.大的蜘蛛也依然是树的结构.输出大的蜘蛛的直径. 知识: 树的直径是指树上的最长简单路 求树的直径有个结论: 假设s-t这条路径为树的直径,或者称为树上的最长路. 从任意一点u出发搜到的最远的点一定是s.t中的一点,然后再从这个最远点开始搜,就可以搜到另一个最长路的端点,即用两遍广搜或者深搜就可以找出树的最长路 证明:反证法. 那回到这道题,要使得大蜘蛛的直径最大,就要使连接的小蜘蛛…
传送门 题目大意 给出一个 1 到 n 的排列,每次操作可以将某个位置的数字移动到最前面或最后面,求将排列从小到大排序的最小操作次数 如:4 1 2 5 3 操作1:将5和3换一下变成4 1 2 3 5 操作2:将1 2 3和 4换一下变成 1 2 3 4 5 在此后即完成要求.所以最小操作次数为2. 输入: 第一行 为长度 nnn ; 第二行为原来的顺序两个数之间有空格. 输出: 最小操作次数 解题思路 因为要从小到大排序,所以我们很自然能想到lis,但是也很容易举出反例.如1 2 4 5 3…
To CF 这道题依题意可得最终答案为序列长度-最长子序列长度. 数据范围至 \(100000\) 用 \(O(n^2)\) 的复杂度肯定会炸. 用 \(O(nlogn)\) 的复杂度却在第 \(21\) 个测试点莫名出错. 于是换一种思路可得 \(dp[s]=dp[s-1]+1\) 即类似于求最长子序列长度. 最后用序列长度-最长子序列长度即为答案. #include<cstdio> #include<iostream> using namespace std; int n; i…
题目链接: 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…
有一家生产酸奶的公司,连续n周,每周需要出货numi的单位,已经知道每一周生产单位酸奶的价格ci,并且,酸奶可以提前生产,但是存储费用是一周一单位s费用,问最少的花费. 对于要出货的酸奶,要不这一周生产,要不提前生产. 什么时候采用什么生产方式呢? 若第i周的货提前生产的话,假设在j周生产,则费用为(i-j)*s+c[j] 若c[i]>(i-j)*s+c[j],则更新c[i]=(i-j)*s+c[j] 更新要O(n^2)? 可以证明,最优的生产方式是,要不在这一周生产,要不在上一周生产(这里的上…
题意:给你一串数,没个数只能往前提到首位,或则往后放末尾.问最少步骤使操作后的序列成上升序列. 思路:最长连续子序列. #include<iostream> #include<stdio.h> #include<stdlib.h> #include<memory.h> #include<string.h> #include<algorithm> #include<cmath> ; ; using namespace std…
The Third Cup is Free Time Limit: 12000/6000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others) Total Submission(s): 1811    Accepted Submission(s): 846 Problem Description Panda and his friends were hiking in the forest. They came across…
Error Correction Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 6825   Accepted: 4289 Description A boolean matrix has the parity property when each row and each column has an even sum, i.e. contains an even number of bits which are set…
CF 628C 题目大意:给定一个长度为n(n < 10^5)的只含小写字母的字符串,以及一个数d,定义字符的dis--dis(ch1, ch2)为两个字符之差, 两个串的dis为各个位置上字符的dis之和,求和给定的字符串的dis为d的字符串,若含有多个则输出任意一个,不存在输出-1 解题思路:简单贪心,按顺序往后,对每一个字符,将其变为与它dis最大的字符(a或者z),d再减去相应的dis, 一直减到d为0,剩余的字母则不变直接输出.若一直到最后一位d仍然大于0,则说明不存在,输出-1. /…
2683: 简单题 Time Limit: 50 Sec  Memory Limit: 128 MBSubmit: 913  Solved: 379[Submit][Status][Discuss] Description 你有一个N*N的棋盘,每个格子内有一个整数,初始时的时候全部为0,现在需要维护两种操作: 命令 参数限制 内容 1 x y A 1<=x,y<=N,A是正整数 将格子x,y里的数字加上A 2 x1 y1 x2 y2 1<=x1<= x2<=N 1<=…
1176: [Balkan2007]Mokia Time Limit: 30 Sec  Memory Limit: 162 MBSubmit: 1854  Solved: 821[Submit][Status][Discuss] Description 维护一个W*W的矩阵,初始值均为S.每次操作可以增加某格子的权值,或询问某子矩阵的总权值.修改操作数M<=160000,询问数Q<=10000,W<=2000000. Input 第一行两个整数,S,W;其中S为矩阵初始值;W为矩阵大小…