hdu 5500 Reorder the Books
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): 942    Accepted Submission(s): 519
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.
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.
4
4 1 2 3
5
1 2 3 4 5
0
假设开始时所有的顺序都是乱的则乱码数为n(即需要移动的步数也为n),从最后一位往前找递减列
找到一个符合的递减序列的元素,乱码数就减少1
#include<stdio.h>
#include<math.h>
#include<string.h>
#include<stdlib.h>
#include<algorithm> using namespace std; const int N = ; int main()
{
int t, n, a[N];
scanf("%d", &t);
while(t--)
{
scanf("%d", &n);
for(int i = ; i <= n ; i++)
scanf("%d", &a[i]);
int x = n;
for(int i = n ; i >= ; i--)
{
if(a[i] == x)
x--;//乱码数
}
printf("%d\n", x);
}
return ;
}
hdu 5500 Reorder the Books的更多相关文章
- HDU 5500 Reorder the Books 贪心
		
Reorder the Books Time Limit: 1 Sec Memory Limit: 256 MB 题目连接 http://acm.hdu.edu.cn/showproblem.php? ...
 - hdu 5500 Reorder the Books(规律)
		
题意: 有一个1→n的排列形成的数列,我们要用最少的操作次数把这个数列从小到大排序,每次操作都是把一个数放到整个数列的最前面. 思路: 首先最大的数n是不用操作的(其他数操作好了,n ...
 - HDU 5500 Reorder the Books (水题)
		
题意: 有n本书,编号为1~n,现在书的顺序乱了,要求恢复成有序的样子,每次只能抽出其中一本并插到最前面,问最少需要多少抽几次? 思路: 如果pos[i]放的不是书i的话,则书i的右边所有的书都必须抽 ...
 - hdoj 5500 Reorder the Books
		
Reorder the Books Time Limit: 4000/2000 MS (Java/Others) Memory Limit: 131072/131072 K (Java/Othe ...
 - 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 ...
 - Reorder the Books -- hdu -- 5500
		
http://acm.hdu.edu.cn/showproblem.php?pid=5500 Reorder the Books Time Limit: 4000/2000 MS (Java/Othe ...
 - Reorder the Books(规律)
		
Reorder the Books Time Limit: 4000/2000 MS (Java/Others) Memory Limit: 131072/131072 K (Java/Othe ...
 - BestCoder Round #59 (div.2) B. Reorder the Books 想法题
		
Reorder the Books 问题描述 dxy家收藏了一套书,这套书叫<SDOI故事集>,<SDOI故事集>有n(n\leq 19)n(n≤19)本,每本书有一个编号,从 ...
 - Reorder the Books-HDU5500
		
Problem Description dxy has a collection of a series of books called "The Stories of SDOI" ...
 
随机推荐
- 矩形最小路径和 · Minimum Path Sum
			
[抄题]: 给定一个只含非负整数的m*n网格,找到一条从左上角到右下角的可以使数字和最小的路径. [思维问题]: [一句话思路]: 和数字三角形基本相同 [输入量]:空: 正常情况:特大:特小:程序里 ...
 - swift  - VFL
			
1.VFL语法总结: //(1)“H”表示水平方向,“V”表示垂直方向 //(2)“|”表示父视图的边界 //(3)“[]”表示这是一个视图UIView的子类,可以组合多个条件,条件用"() ...
 - Java中的NIO及IO
			
1.概述 Java NIO(New IO) 是从Java 1.4版本开始引入的一个新的IO API,可以替代标准的Java IO API.NIO与原来的IO有同样的作用和目的,但是使用的方式完全不同, ...
 - WebApi是轻量级的,WCF是重量级的,可以Api调用WCF,更灵活
			
WCF.WebAPI.WCFREST.WebService之间的区别 注明:转载 在.net平台下,有大量的技术让你创建一个HTTP服务,像Web Service,WCF,现在又出了Web API.在 ...
 - Django之virtualenv下安装xadmin
			
1.安装xadmin,通过pip 进入virtualenv pip安装xadmin pyyuc:~ yuchao$ source PycharmProjects/mxvenv/bin/activate ...
 - MySql中4种批量更新的方法
			
最近在完成MySql项目集成的情况下,需要增加批量更新的功能,根据网上的资料整理了一下,很好用,都测试过,可以直接使用. mysql 批量更新共有以下四种办法 1..replace into 批量更新 ...
 - 1、HttpClient初探
			
HttpClient是它的核心接口.可以理解为一个简单的浏览器. 主要方法有: getParams(); 获取运行参数 getConnectionManager(); 获取连接管理器.连接管理器中 ...
 - 2018.10.09 NOIP模拟 路途(递推+矩阵快速幂优化)
			
传送门 签到题.(考试的时候写挂爆0) 令AiA_iAi表示邻接矩阵的iii次幂. 于是就是求Al+Al+1+...+ArA_l+A_{l+1}+...+A_rAl+Al+1+...+Ar. ...
 - 2018.09.11 poj1845Sumdiv(质因数分解+二分求数列和)
			
传送门 显然需要先求出ab" role="presentation" style="position: relative;">abab的所有质因 ...
 - 2018.07.18 [NOI2018]归程(return)(kruskal重构树)
			
传送门 新鲜出炉的noi2018试题. 下面讲讲这题的解法: 首先要学习一个叫做kruskal重构树的东东. 听名字就知道跟kruskal算法有关,没错,原来的kruskal算法就是用并查集实现的,但 ...