http://acm.hdu.edu.cn/showproblem.php?pid=5500

Reorder the Books

Time Limit: 4000/2000 MS (Java/Others)    Memory Limit: 131072/131072 K (Java/Others)
Total Submission(s): 920    Accepted Submission(s): 502

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>
#define N 110000 int a[N]; int main()
{
int T;
scanf("%d", &T);
while(T--)
{
int n, i;
scanf("%d", &n); memset(a, , sizeof(a));
for(i=; i<n; i++)
scanf("%d", &a[i]); int ans=n, an=; for(i=n-; i>=; i--)
{
if(ans==a[i])
ans--;
else
an++;
}
printf("%d\n", an);
}
return ;
}

Reorder the Books -- hdu -- 5500的更多相关文章

  1. HDU 5500 Reorder the Books 贪心

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

  2. hdu 5500 Reorder the Books

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

  3. hdoj 5500 Reorder the Books

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

  4. 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 ...

  5. Reorder the Books(规律)

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

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

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

  7. hdu 5500 Reorder the Books(规律)

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

  8. HDU 5500 Reorder the Books (水题)

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

  9. Reorder the Books-HDU5500

    Problem Description dxy has a collection of a series of books called "The Stories of SDOI" ...

随机推荐

  1. redis 数据类型为string命令整理以及示例

    #设置值 SET key value [EX seconds] [PX milliseconds] [NX|XX] SET命令加上选项已经可以完全取代SETNX, SETEX, PSETEX的功能,所 ...

  2. Invalid character found in the request target. The valid characters are defined in RFC 7230 and RFC 3986

    最近在Tomcat上配置一个项目,在点击一个按钮,下载一个文件的时候,老是会报上面的错误.试了很多方法,如对server.xml文件中,增加MaxHttpHeaderSize的大小,改端口,改Tomc ...

  3. mysql 5.7.17 建立主从数据库

    ---恢复内容开始--- 1.确定主/从数据库地址; 2.将主数据库的database dump出来 windows平台用workbench; 其他可以参考: 这位同仁写的比较详细了.我就不谢了.打开 ...

  4. 使用iTEXT库生成pdf

    iTEXT下载地址 https://sourceforge.net/projects/itext/files/ 选择绿色的按钮,下载最新版本,解压后是一些jar包 为了使用方便,将文件夹放到JAVA_ ...

  5. vue脚手架搭建的具体步骤

    1.全局安装cli npm install -g vue-cli 在全局安装vue的命令行工具 2.初始化项目 vue init webpack my-project   初始化一个基于webpack ...

  6. iphone手机safari浏览器访问网站滚动条不显示问题解决办法

    近排有公司同事出差在外需使用OA系统,发现iphone手机safari浏览器在该出现滚动条的页面没有显示滚动条,导致无法正常使用. 系统前端页面是采用jeasyui搭建的框架,使用iframe变更主页 ...

  7. javase高级技术 - 泛型

    在写案例之前,先简单回顾下泛型的知识 我们知道,java属于强变量语言,使用变量之前要定义,并且定义一个变量时必须要指明它的数据类型,什么样的数据类型赋给什么样的值. 所谓“泛型”,就是“宽泛的数据类 ...

  8. 【算法】DP解决旅行路径问题

    问题描述 : After coding so many days,Mr Acmer wants to have a good rest.So travelling is the best choice ...

  9. 几种开源的TCP/IP协议栈分析

    1:BSD TCP/IP协议栈,BSD栈历史上是其他商业栈的起点,大多数专业TCP/IP栈(VxWorks内嵌的TCP/IP栈)是BSD栈派生的.这是因为 BSD栈在BSD许可协议下提供了这些专业栈的 ...

  10. Keras的泰坦尼克号的生存率的数据分析

      # coding: utf-8 # In[1]: import urllib.request import os # In[2]: url="http://biostat.mc.vand ...