HDU Reorder the Books 找规律
来源:互联网 发布:数组tostring 编辑:程序博客网 时间:2024/05/24 23:12
题目:
http://acm.hdu.edu.cn/showproblem.php?pid=5500
这道题与之前做过的一道题很像,但比那道题简单;
思路:对于一个序列,我们最多用n-1不就可以将它排好序;
而最大值一定在最下面,所以我们先找到最大值的位置;
找出从它开头向上找出连续的子序列tot,这个子序列上的数可以不用移动;
ans=ans-tot
#include<iostream>#include<cstdio>#include<cstring>#include<algorithm>using namespace std;int m,n;int a[1000001];int pos[1000001];void solve(){ scanf("%d",&n); for(int i=1;i<=n;i++) a[i]=pos[i]=0; for(int i=1;i<=n;i++) scanf("%d",&a[i]),pos[a[i]]=i; int ans=n-1; int i=pos[n],t=n-1; while(true) { i--; if(!i) break; if(a[i]==t) ans--,t--; } cout<<ans<<'\n'; return;}int main(){ cin>>m; while(m--) solve(); return 0;}
阅读全文
0 0
- HDU Reorder the Books 找规律
- HDU 5500:Reorder the Books【规律】
- HDU 5500 Reorder the Books (规律)
- HDU 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
- 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
- HDOJ-5500Reorder the Books(规律)
- hdoj 5500 Reorder the Books 【规律】
- hdoj 5500Reorder the Books【规律】
- 希尔排序
- 数据结构实验之二叉树二:遍历二叉树
- 20171106
- 计数系统架构实践一次搞定
- VUE项目的小坑
- HDU Reorder the Books 找规律
- history对象
- HDU
- AHB笔记
- 判断学生成绩是否有效
- 【java集合】HashMap源码解析
- 枚举的学习之路一
- 滚动条
- <<游戏人工智能编程案例精粹>>读书笔记二