HDU 5500 Reorder the Books
来源:互联网 发布:php 直播功能如何实现 编辑:程序博客网 时间:2024/06/16 20:25
题目
https://vjudge.net/problem/HDU-5500
题意是说给你一个打乱顺序的区间,要求变成从小到大排列。每次移动一个数的时候都要把这个数放到区间的最前面,问最少的变成目标区间的操作次数。
题解
http://blog.csdn.net/Loi_black/article/details/78441083
原题的数据范围很水,可以做到O(N*T)
考虑最糟糕的情况,我们固定最大的元素不动,把其他所有元素按照一定顺序向上丢,这样一定能得到答案。
如果有一个比最大数小的次大数在最大数的上方,显然这个次大数是不必被丢的,ans-1
,同理,次大和次次大也是这样
【困成狗,看black学长博客吧】
代码
#include<iostream>#include<cstdio>using namespace std;const int N=1000000+50;int a[N],mp[N];int n,nowwz,now,ans;int main(){ int t; scanf("%d",&t); while(scanf("%d",&n)!=EOF){ for(int i=1;i<=n;i++){ scanf("%d",&a[i]); mp[a[i]]=i; } ans=n-1; int now=n,nowwz=mp[now]; for(;;){ if(now==1) break; now--; if(nowwz>mp[now]){ ans--; nowwz=mp[now]; }else break; } printf("%d\n",ans); }}
阅读全文
0 0
- HDU 5500 Reorder the Books
- HDU 5500 Reorder the Books
- hdu 5500 Reorder the books
- hdu 5500 Reorder the Books
- HDU 5500 Reorder the Books
- hdu 5500 Reorder the Books
- HDU 5500 Reorder the Books
- Reorder the Books HDU - 5500
- HDU 5500 Reorder the Books
- HDU 5500 Reorder the Books
- HDU Reorder the Books
- hdu 5500 Reorder the Books(模拟)
- HDU 5500 Reorder the Books(模拟)
- Reorder the Books-HDU-5500-BC59div2
- hdu acm 5500 Reorder the Books
- hdu 5500 Reorder the Books(贪心)
- HDU 5500:Reorder the Books【规律】
- HDU 5500 Reorder the Books【水题】
- 数据结构-各类树
- 计算机视觉·常用数据集·3D
- 解决:redis添加hash数据失败问题
- 构建基于Node.js的web应用
- Java的内存机制
- HDU 5500 Reorder the Books
- maven生命周期(lifecycle)—— maven权威指南学习笔记(四)
- TCP/IP协议族【第五章IPV4地址】
- 商业web漏扫神器——appscan篇
- 众数问题
- Linux—学习记录_Shell Script脚本
- linux初学之lvm动态扩容管理
- 洛谷八连测 #R8
- redis事物介绍