题干:

dxy has a collection of a series of books called "The Stories of SDOI",There are n(n≤19)n(n≤19) books in this series.Every book has a number from 11 to nn.

dxy puts these books in a book stack with the order of their numbers increasing from top to bottom. dxy takes great care of these books and no one is allowed to touch them.

One day Evensgn visited dxy's home, because dxy was dating with his girlfriend, dxy let Evensgn stay at home himself. Evensgn was curious about this series of books.So he took a look at them. He found out there was a story about "Little E&Little Q". While losing himself in the story,he disrupted the order of the books.

Knowing that dxy would be back soon,Evensgn needed to get the books ordered again.But because the books were too heavy.The only thing Evensgn could do was to take out a book from the book stack and and put it at the stack top.

Give you the order of the disordered books.Could you calculate the minimum steps Evensgn would use to reorder the books? If you could solve the problem for him,he will give you a signed book "The Stories of SDOI 9: The Story of Little E" as a gift.

Input

There are several testcases.

There is an positive integer T(T≤30)T(T≤30) in the first line standing for the number of testcases.

For each testcase, there is an positive integer nn in the first line standing for the number of books in this series.

Followed nn positive integers separated by space standing for the order of the disordered books,the ithith integer stands for the ithith book's number(from top to bottom).

Hint: 
For the first testcase:Moving in the order of book3,book2,book1book3,book2,book1 ,(4,1,2,3)→(3,4,1,2)→(2,3,4,1)→(1,2,3,4)(4,1,2,3)→(3,4,1,2)→(2,3,4,1)→(1,2,3,4),and this is the best way to reorder the books. 
For the second testcase:It's already ordered so there is no operation needed.

Output

For each testcase,output one line for an integer standing for the minimum steps Evensgn would use to reorder the books.

Sample Input

2
4
4 1 2 3
5
1 2 3 4 5

Sample Output

3
0

题目大意:

有n本带编号的书,现在给你打乱了顺序,定义一次操作可以任选一本书并且放到最顶部。问你最少需要多少次操作可以将这一摞书调整为有序(编号从小到大)?

解题报告:

直接模拟就行了。。先找出来需要移动多少本书,假设是x本,那么肯定可以通过x次操作还原回来。

AC代码:

#include<cstdio>
#include<iostream>
#include<algorithm>
#include<queue>
#include<map>
#include<vector>
#include<set>
#include<string>
#include<cmath>
#include<cstring>
#define ll long long
#define pb push_back
#define pm make_pair
#define fi first
#define se second
using namespace std;
const int MAX = 2e5 + 5;
int ji,ou,all,n;
int a[MAX];
int main()
{int t;cin>>t;while(t--) {cin>>n;for(int i = 1; i<=n; i++) scanf("%d",a+i);int now = n,ans=0;for(int i = n; i>=1; i--) {if(now == a[i]) now--;else ans++;}printf("%d\n",ans);} return 0 ;}

【HDU - 5500】 Reorder the Books (思维)相关推荐

  1. HDU 6092 Rikka with Subset 思维 递推

    题目链接: http://acm.hdu.edu.cn/showproblem.php?pid=6092 题目描述: 给你一个集合的所有子集各个和, 让你找到这个集合, 输出字典序最小 解题思路: 下 ...

  2. hdu 4747 mex 线段树+思维

    http://acm.hdu.edu.cn/showproblem.php?pid=4747 题意: 我们定义mex(l,r)表示一个序列a[l]....a[r]中没有出现过得最小的非负整数, 然后我 ...

  3. HDU 6090 Rikka with Graph 思维 公式

    题目链接: http://acm.hdu.edu.cn/showproblem.php?pid=6090 题目描述: 有n个点, 你可以连m条边, 使得∑ni=1∑nj=1dist(i,j).最小, ...

  4. HDU - 5976 Detachment(贪心思维)

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=5976 题意:把一个数拆成若干个不相同的数之和,问这些数的乘积最大是多少. 思路:一般要使乘积最大,那么 ...

  5. HDU 6040 Hints of sd0061 思维

    题目链接: http://acm.hdu.edu.cn/showproblem.php?pid=6040 题目大意: 给定数组a, b.要求输出和B长度相同的数组C, C[i]为在A中排名为B[i]的 ...

  6. 2018icpc青岛Books 思维

    题意: DreamGrid went to the bookshop yesterday. There are books in the bookshop in total. Because Drea ...

  7. HDU - 5521 Meeting(最短路+思维建边)

    题目链接:点击查看 题目大意:给出 n 个点,再给出 m 个集合,对于每个集合中的点来说,其两两都是相互可达的,且花费都相同,问有多少个点,到达点 1 和点 n 的距离相同且最小 题目分析:因为每个集 ...

  8. HDU - 4292 Food(最大流+思维建边)

    题目链接:点击查看 题目大意:作为食堂管理人,现在有n个学生需要打饭,每个学生需要一个饮料和食物才能满足,每个学生可以同时接受多种不同的食物和饮料,现在给出每种食物和饮料的个数,问最多能让多少学生满足 ...

  9. HDU - 3530 Subsequence(单调队列+思维)

    题目链接:点击查看 题目大意:给出一段长度为n的序列,现在给出一个m和一个k,必须满足一段连续区间内的最大值与最小值的差值大于等于m并且小于等于k,问满足条件的连续区间的最大长度 题目分析:一开始看到 ...

最新文章

  1. DARPA 2020财年研发预算 人工智能应用研究投资急剧增长
  2. 并行博弈树搜索算法-第6篇 百花齐放:各种并行Alpha-Beta算法
  3. android源码编译 简书,android学习笔记之源码编译
  4. 【Java 网络编程】UDP 简介
  5. Kafka auto.offset.reset
  6. STM32F103/302 SPI3 接口使用例程
  7. Linux /etc/profile文件详解
  8. jMeter 打开项目时遇到错误消息 CannotResolveClassException: com.blazemeter.jmeter.RandomCSVDataSetConfig
  9. The Model Driven Software Network
  10. 单片机快速将库函数版代码移植为寄存器代码方法
  11. Linux入门-安装篇(Debian 服务器版)
  12. 经典神经网络 -- DPN : 设计原理与pytorch实现
  13. 【通信仿真】基于matlab V-BLAST结构检测算法仿真【含Matlab源码 1683期】
  14. 碳中和数据全集-最全碳排放、碳封存、碳排放权配额、碳交易、能源消费与二氧化碳排放
  15. 人工智能(AI)经历了怎样的发展历程?
  16. 服务器的硬件设备及raid
  17. 通信(一) 串口通信
  18. win7 windows update 无法更新错误代码80072EF
  19. Jetson nano 使用ROS 实现串口通信,并且解析通信协议(C++)
  20. Linux服务器如何开启某个端口?

热门文章

  1. 【数据结构与算法】排序优化
  2. PHP与MySQL案例剖析_PHP与MySQL案例剖析
  3. windows键盘在mac上怎么识别_Mac电脑怎么使用pc键盘?
  4. java nextintln_java – 从lambda表达式引用的局部变量必须是final或者有效的final
  5. pcb板子开窗_PCB 层定义
  6. c语言math函数 sgn,常用矩阵计算C语言代码
  7. python图灵测试_最前沿:基于GAN和RL的思想来训练对话生成,通过图灵测试可期!...
  8. python代做在哪找靠谱_比较靠谱的资产评估师考试去哪找
  9. 指定一个actor对pawn不可见
  10. Linux下gSOAP的使用 (c++)