hdoj 5500 Reorder the Books
Reorder the Books
Time Limit: 4000/2000 MS (Java/Others)    Memory Limit: 131072/131072 K (Java/Others)
Total Submission(s): 919    Accepted Submission(s):
501
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.
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.
standing for the minimum steps Evensgn would use to reorder the books.
#include<stdio.h>
#include<string.h>
#include<algorithm>
#define MAX 100100
using namespace std;
int a[MAX];
int main()
{
int n,m,t,i,j;
scanf("%d",&t);
int maxx,ans;
while(t--)
{
scanf("%d",&n);
maxx=0;
for(i=1;i<=n;i++)
{
scanf("%d",&a[i]);
if(maxx<a[i])
{
maxx=a[i];
ans=i;
}
}
int ant=ans,sum=0;
for(j=ans;j>=1;j--)
{
if(a[j]==a[ant]-1)
{
sum++;
ant=j;
}
}
printf("%d\n",n-sum-1);
}
return 0;
}
hdoj 5500 Reorder the Books的更多相关文章
- 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 ...
 - hdu 5500  Reorder the Books
		
http://acm.hdu.edu.cn/showproblem.php?pid=5500 Reorder the Books Time Limit: 4000/2000 MS (Java/Othe ...
 - 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的右边所有的书都必须抽 ...
 - 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" ...
 
随机推荐
- [杂题]FZU2190 非提的救赎
			
中文题,题意不多说. 本来感觉很像dp 其实只要从上到下维护单调性就好了 坑是......这个oj......用cin很容易TLE...... //#include <bits/stdc++.h ...
 - highChartTable 切换
			
<!doctype html> <html lang="en"> <head> <script type="text/javas ...
 - Java API ——String类
			
1.String类概述 · 字符串是由多个字符组成的一串数据(字符序列),也可以看成是一个字符数组. · 字符串字符值“abc”也可以看成是一个字符串对象. · 字符串是常量,一旦被赋值,就不能被改变 ...
 - 在安装ISE的情况下,充分利用ISE的安装目录,查找资料
			
2013-06-22 11:03:02 在找资料时,通过官网输入关键字的方法找资料,有事会给出很多版本的链接.或者找不到,下面给出一种简便的方法,可以快速找到想要的资料. 如果要找ISE各个工具如pl ...
 - JavaScript DOM高级程序设计1.3-常见陷阱--我要坚持到底!
			
区分大小写 单引号双引号 大多数开发人员选择用单引号,因为XTHML要求所有XHTML的属性都必须使用双引号 var html='<h2 class="a">A lis ...
 - Complete The Pattern #1
			
Complete The Pattern #1 Task: You have to write a function pattern which creates the following patte ...
 - Return Negative
			
Return Negative In this simple assignment you are given a number and have to make it negative. But m ...
 - java.lang.NoClassDefFoundError: com/opensymphony/xwork2/util/TextUtils
			
java.lang.NoSuchMethodError: com.opensymphony.xwork2.ActionContext.get(Ljava/lang/String;)Ljava/lang ...
 - javascript中this的使用
			
终于知道某些大神在写js插件的时候为什么第一句都是"var that=this",来看看下面的这个例子,大家都会懂啦: <script type="text/jav ...
 - oracle必须启动的服务
			
按照windows 7 64位 安装oracle 11g R2中的方法成功安装Oracle 11g后,共有7个服务,这七个服务的含义分别为: 1. Oracle ORCL VSS Writer Ser ...