Reorder the Books

Time Limit: 4000/2000 MS (Java/Others)    Memory Limit: 131072/131072 K (Java/Others)

Total Submission(s): 930    Accepted Submission(s): 511

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



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)
in the first line standing for the number of testcases.



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



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





Hint:

For the first testcase:Moving in the order of book3,book2,book1
,(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
 
Source

#include<stdio.h>
#include<string.h>
int a[1010];
int main()
{
int t;
scanf("%d",&t);
while(t--)
{
int n;
scanf("%d",&n);
int m=n;
for(int i=1;i<=n;i++)
scanf("%d",&a[i]);
for(int i=n;i>=1;i--)
{
if(m==a[i])
m--;
}
printf("%d\n",m);
}
return 0;
}

hdoj--5500--Reorder the Books(技巧)的更多相关文章

  1. hdoj 5500 Reorder the Books

    Reorder the Books Time Limit: 4000/2000 MS (Java/Others)    Memory Limit: 131072/131072 K (Java/Othe ...

  2. BestCoder Round 59 (HDOJ 5500) Reorder the Books

    Problem Description dxy has a collection of a series of books called “The Stories of SDOI”,There are ...

  3. hdu 5500 Reorder the Books

    http://acm.hdu.edu.cn/showproblem.php?pid=5500 Reorder the Books Time Limit: 4000/2000 MS (Java/Othe ...

  4. HDU 5500 Reorder the Books 贪心

    Reorder the Books Time Limit: 1 Sec Memory Limit: 256 MB 题目连接 http://acm.hdu.edu.cn/showproblem.php? ...

  5. hdu 5500 Reorder the Books(规律)

    题意:   有一个1→n的排列形成的数列,我们要用最少的操作次数把这个数列从小到大排序,每次操作都是把一个数放到整个数列的最前面. 思路:        首先最大的数n是不用操作的(其他数操作好了,n ...

  6. HDU 5500 Reorder the Books (水题)

    题意: 有n本书,编号为1~n,现在书的顺序乱了,要求恢复成有序的样子,每次只能抽出其中一本并插到最前面,问最少需要多少抽几次? 思路: 如果pos[i]放的不是书i的话,则书i的右边所有的书都必须抽 ...

  7. Reorder the Books -- hdu -- 5500

    http://acm.hdu.edu.cn/showproblem.php?pid=5500 Reorder the Books Time Limit: 4000/2000 MS (Java/Othe ...

  8. Reorder the Books(规律)

    Reorder the Books Time Limit: 4000/2000 MS (Java/Others)    Memory Limit: 131072/131072 K (Java/Othe ...

  9. BestCoder Round #59 (div.2) B. Reorder the Books 想法题

    Reorder the Books 问题描述 dxy家收藏了一套书,这套书叫<SDOI故事集>,<SDOI故事集>有n(n\leq 19)n(n≤19)本,每本书有一个编号,从 ...

随机推荐

  1. gdbserver 远程调试问题:设置文件和so搜索路径

    编写一个必定crash 的程序 #include <stdio.h> void crash(){ char *a=0; *a=0; } int main() { printf(" ...

  2. angularjs1-过滤器

    <!DOCTYPE html> <html> <body> <header> <meta http-equiv="Content-Typ ...

  3. Java-MyBatis-杂项: MyBatis 中 in 的用法2

    ylbtech-Java-MyBatis-杂项: MyBatis 中 in 的用法2 1.返回顶部 1. 一.简介 在SQL语法中如果我们想使用in的话直接可以像如下一样使用: select * fr ...

  4. element-ui自定义table表头,修改列标题样式

    elementUI table表格一般的样式是这样的: 但是要改变表头是比较麻烦的一个事情,但是往往有些项目是需要的比如改成如下样式: 一般直接改起来挺麻烦,好在官网提供了一个方法:render-he ...

  5. Spark on YARN运行模式(图文详解)

    不多说,直接上干货! 请移步 Spark on YARN简介与运行wordcount(master.slave1和slave2)(博主推荐) Spark on YARN模式的安装(spark-1.6. ...

  6. Comparison of programming languages

    The following table compares general and technical information for a selection of commonly used prog ...

  7. AC Codeforces Round #499 (Div. 2) E. Border 扩展欧几里得

    没想出来QAQ....QAQ....QAQ.... 对于一般情况,我们知道 ax+by=gcd(a,b)ax+by=gcd(a,b)ax+by=gcd(a,b) 时方程是一定有解的. 如果改成 ax+ ...

  8. jq——事件

    http://www.w3school.com.cn/jquery/jquery_ajax_intro.asp $(document),$(body) 加载事件: $(document).ready( ...

  9. NOIP2013 华容道 (棋盘建图+spfa最短路)

    #include <cstdio> #include <algorithm> #include <cstring> #include <queue> # ...

  10. freeswitch 注册错误408 - Request Timeout

    1.网络不通(可能虚拟机没打开网络) 2.防火墙没有过滤端口号(关闭防火墙) 3.IP地址错误