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" ...
随机推荐
- HeadFirst设计模式之组合模式
一. 1.The Composite Pattern allows us to build structures of objects in the form of trees that contai ...
- WinAPI你知道多少?!(上千个,好多都没见过)
http://www.cnblogs.com/vanver/archive/2013/06/13/NO-2013_06_13pm.html 播客开篇,讲讲废话:本篇播客只是推荐给热与钻研的同学们... ...
- 221. Maximal Square
题目: Given a 2D binary matrix filled with 0's and 1's, find the largest square containing all 1's and ...
- R语言笔记:快速入门
1.简单会话 > x<-c(1,2,4) > x [1] 1 2 4 R语言的标准赋值运算符是<-.也可以用=,不过不建议用它,有些情况会失灵.其中c表示连接(concaten ...
- 蓝牙(2)用BluetoothAdapter搜索蓝牙设备示例
注意在搜索之前要先打开蓝牙设备 package com.e.search.bluetooth.device; import java.util.Set; import android.app.Acti ...
- Ubuntu设置中文
Ubuntu设置中文:需要联网下载中文包,不然无法设置中文系统. 进去系统后再右上角有个齿轮图标点击,找到系统设置(System Settings)点击弹出一个界面,找到Language Suppor ...
- MAX-HEAPIFY(2/3n的疑惑)
Q: In CLRS, third Edition, on page 155, it is given that in MAX-HEAPIFY, The children’s subtrees eac ...
- UVa 1606 (极角排序) Amphiphilic Carbon Molecules
如果,没有紫书上的翻译的话,我觉得我可能读不懂这道题.=_=|| 题意: 平面上有n个点,不是白点就是黑点.现在要放一条直线,使得直线一侧的白点与另一侧的黑点加起来数目最多.直线上的点可以看作位于直线 ...
- Java 7 Fork/Join 并行计算框架概览
应用程序并行计算遇到的问题 当硬件处理能力不能按摩尔定律垂直发展的时候,选择了水平发展.多核处理器已广泛应用,未来处理器的核心数将进一步发布,甚至达到上百上千的数量.而现在 很多的应用程序在运行在多核 ...
- 《C#并行编程高级教程》第8章 线程池 笔记
主要的几个概念(详细最好还是看书,配合插图看) 任务是会被分配到线程上的,而这些线程都在线程池引擎下管理 线程池引擎管理着合适数量的线程池,线程从全局队列获取工作项执行. .NET4 Framew ...