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" ...
随机推荐
- DAO是什么技术
DAO是Data Access Object数据访问接口,数据访问:故名思义就是与数据库打交道.夹在业务逻辑与数据库资源中间. 在核心J2EE模式中是这样介绍DAO模式的:为了建立一个健壮的J2EE应 ...
- 算法总结之欧拉函数&中国剩余定理
算法总结之欧拉函数&中国剩余定理 1.欧拉函数 概念:在数论,对正整数n,欧拉函数是少于或等于n的数中与n互质的数的数目. 通式:φ(x)=x(1-1/p1)(1-1/p2)(1-1/p3)( ...
- 转:JavaScript中函数与对象的关系
来自:http://www.nowamagic.net/javascript/js_RelationOfFunctionAndObject.php 在ajax兴起以前,很多人写JavaScript可以 ...
- etc/ld.so.conf的使用说明
这个文件记录了编译时使用的动态链接库的路径.默认情况下,编译器只会使用/lib和/usr/lib这两个目录下的库文件如果你安装了某些库,比如在安装gtk+-2.4.13时它会需要glib-2.0 &g ...
- android从应用到驱动之—camera(1)---程序调用流程[转]
一.开篇 写博客还得写开篇介绍,可惜,这个不是我所擅长的.就按我自己的想法写吧. 话说camera模块,从上层到底层一共包含着这么几个部分: 1.apk------java语言 2.camera的ja ...
- VMware Workstation与Hyper-V不兼容。请先从系统中移除Hyper-V角色,然后再运行VMware Workstation。
VMware Workstation与Hyper-V不兼容.请先从系统中移除Hyper-V角色,然后再运行VMware Workstation. 今天在用win8.1的时候发现了这个问题,解决办法如下 ...
- javacript序列化表单数据
在前端开发时,用到表单交互的比较多,在我们实现一些异步操作数据时,表单数据的序列化就显得尤为重要了.下面我们一起来看看如何进行序列化. 如,我们在进行提交表单时,地址栏里会显示这样的东东:name=z ...
- Android 内存管理(二)
很多开发者都是从j2me或j2ee上过来的,对于内存的使用和理解并不是很到位,Android开发网本次给大家一些架构上的指导,防止出现豆腐渣工 程的出现.Android作为以Java语言为主的智能平台 ...
- 中国海洋大学第四届朗讯杯高级组 Cash Cow(模拟)
题目:http://acm.sdut.edu.cn/sdutoj/problem.php?action=showproblem&problemid=2721 题意: 给定n个左标,跟那n个坐标 ...
- UVa 1451 (数形结合 单调栈) Average
题意: 给出一个01串,选一个长度至少为L的连续子串,使得串中数字的平均值最大. 分析: 能把这道题想到用数形结合,用斜率表示平均值,我觉得这个想法太“天马行空”了 首先预处理子串的前缀和sum,如果 ...