BNU 49048 神奇的身高【思维+LIS】
2017-05-08 23:09
435 查看
神奇的身高
Time Limit: 2000msMemory Limit: 65536KB
64-bit integer IO format: %lld
Java class name: Main
Prev
Submit Status Statistics Discuss
Next
Type:
None
NoneGraph Theory
2-SAT Articulation/Bridge/Biconnected Component
Cycles/Topological Sorting/Strongly Connected Component
Shortest Path
Bellman Ford Dijkstra/Floyd Warshall
Euler Trail/Circuit
Heavy-Light Decomposition Minimum Spanning Tree
Stable Marriage Problem
Trees Directed Minimum Spanning Tree
Flow/Matching
Graph Matching Bipartite Matching
Hopcroft–Karp Bipartite Matching
Weighted Bipartite Matching/Hungarian Algorithm
Flow
Max Flow/Min Cut Min Cost Max Flow
DFS-like
Backtracking with Pruning/Branch and Bound
Basic Recursion IDA* Search
Parsing/Grammar Breadth First Search/Depth First Search
Advanced Search Techniques
Binary Search/Bisection Ternary Search
Geometry
Basic Geometry Computational Geometry
Convex Hull
Pick's TheoremGame Theory
Green Hackenbush/Colon Principle/Fusion Principle
Nim Sprague-Grundy Number
Matrix Gaussian Elimination
Matrix ExponentiationData Structures
Basic Data Structures Binary Indexed Tree
Binary Search Tree
Hashing Orthogonal Range Search
Range Minimum Query/Lowest Common Ancestor
Segment Tree/Interval Tree Trie Tree
Sorting
Disjoint SetString
Aho Corasick Knuth-Morris-Pratt
Suffix Array/Suffix TreeMath
Basic Math Big Integer Arithmetic
Number Theory Chinese Remainder Theorem
Extended Euclid
Inclusion/Exclusion Modular Arithmetic
Combinatorics
Group Theory/Burnside's lemma Counting
Probability/Expected Value
Others Tricky
Hardest Unusual
Brute Force Implementation
Constructive Algorithms Two Pointer
Bitmask Beginner
Discrete Logarithm/Shank's Baby-step Giant-step Algorithm
Greedy Divide and Conquer
Dynamic Programming
Tag it!
有一群小伙伴站成一行,每个人的身高都是非负整数,但是他们站在一起并不和谐。需要将他们的身高变成严格单调递增的正整数序列才是和谐的。现在你有一种神奇的魔法,可以任意改变一个人的身高。现在问题来了,你最少需要改变多少人的身高才能使整个队伍和谐。(改变后的身高必须为整数)
Input
有多组测试数据,保证大数据不超过15组。每组测试数据:
第1行:一个数n表示人数(1≤n≤100000)
第2~n+1行:每行1个数,对应数组的元素(0≤A[i]≤10^9)
以EOF结束
Output
输出最少需要修改几人的身高才能使整个队伍和谐。
Sample Input
2 1 2 2 2 1
Sample Output
0 1
Source
第十三届北京师范大学程序设计竞赛决赛
Author
zpk思路:
本题和百度之星hdu 5256比较相似。
我们希望得到一个序列为:1 2 3 4 5 6 7 8 9 10...................
那么我们不妨相对得到即可。
所以我们跑(a【i】-i)的LIS(这里跑最长非递减)就行。
但是这里要求数据最终不能有<=0的数据存在,那么所以如果a【i】-i<0,就一定不属于LIS的部分,因为其如果属于了,又参与到了最长上升子序列中了,那么结果就会出现负数的情况。
所以我们只要对于(a【i】-i)>0的部分跑LIS即可。
Ac代码:
#include<stdio.h> #include<algorithm> #include<string.h> using namespace std; int a[1050000]; int f[1050000]; int Slove(int n) { int c=0; for(int i=1; i<=n; i++) { int t=a[i]; if(t<0)continue; if(i==1) f[++c]=t; else { if(t>=f[c]) f[++c]=t; else { int pos=upper_bound(f+1,f+c,t)-f;//二分找到数组中比t大的第一个元素的的地址。 f[pos]=t; } } } return c; } int main() { int n; while(~scanf("%d",&n)) { for(int i=1;i<=n;i++) { int x; scanf("%d",&x); a[i]=x-i; } printf("%d\n",n-Slove(n)); } }
相关文章推荐
- BNUOJ49098 神奇的身高(LIS)
- BNUOJ49098 神奇的身高 - DP (LIS)
- BNU 49098 神奇的身高
- 神奇的二叉查找树,停不下来的思维风暴,来这里,我将告诉你它的实现原理
- Gym100820G/UVALive7374 Racing Gems 二维LIS 思维题
- HDU:5256 序列变换(LIS-n*logn解法+思维+技巧)
- 神奇的身高
- BZOJ 1257: [CQOI2007]余数之和sum【神奇的做法,思维题】
- hdu 5773 The All-purpose Zero 思维转化+nlogn LIS
- bnu1209 1-->0的神奇游戏 C语言版
- 【HDU】-5773-The All-purpose Zero(LIS变形,思维)
- BNU 51645 ACM Battle【思维+爆搜】确实挺隐秘的一个爆搜题
- Codeforces 757C Felicity is Coming!【思维+vector应用】STL好神奇啊!
- CCCC-GPLT L2-014. 列车调度 思维/LIS
- HDU:1025 Constructing Roads In JGShining's Kingdom(LIS-n*logn解法+思维)
- BNU49098:神奇的身高
- Gym - 101246H ``North-East''【思维+nlogn LIS】
- (45) 神奇的堆 / 计算机程序的思维逻辑
- bnuoj49098 神奇的身高
- bnu1258 神奇礼物盒 C语言版