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): 930 Accepted Submission(s): 511
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.
2
4
4 1 2 3
5
1 2 3 4 5
3
0
#include<stdio.h>
#include<string.h>
int a[1010];
int main()
{
int t;
scanf("%d",&t);
while(t--)
{
int n;
scanf("%d",&n);
int m=n;
for(int i=1;i<=n;i++)
scanf("%d",&a[i]);
for(int i=n;i>=1;i--)
{
if(m==a[i])
m--;
}
printf("%d\n",m);
}
return 0;
}
hdoj--5500--Reorder the Books(技巧)的更多相关文章
- 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 ...
- 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)本,每本书有一个编号,从 ...
随机推荐
- Oracle 性能优化的基本方法
Oracle 性能优化的基本方法概述 1)设立合理的性能优化目标. 2)测量并记录当前性能. 3)确定当前Oracle性能瓶颈(Oracle等待什么.哪些SQL语句是该等待事件的成分). 4)把等待事 ...
- ubuntu16.04 安装 docker-compose
下载安装 docker-composecurl -L https://github.com/docker/compose/releases/download/1.15.0/docker-compose ...
- Core Java(六)
面向对象语言特性 (一) (一) static 作用于 变量,方法,代码块 静态变量:被类的所有对象共享 在类加载时被加载 优先于对象 Student.country = "中国& ...
- SQL学习——基础语句(3)
先上数据表 student表 grade 表 SQL Union 语句 合并两个或多个select查询结果集. select s_id from student union select s_id ...
- Java 集合类的细节
java集合类 1.Collection,Map层次图 2.Collection接口 list 存放有序且允许重复的集合的接口 这里的有序是指存入顺序和取出顺序相同.子类有:{ ArrayList,L ...
- 在centos上安装php5.5+MySQL 5.5.32
在centos直接使用yum install 安装php的话版本比较低,如果需要高版本的话,请看如下: Step 1: Installing Remi Repository ## Install Re ...
- poj 2135 Farm Tour【 最小费用最大流 】
第一道费用流的题目--- 其实---还是不是很懂,只知道沿着最短路找增广路 建图 源点到1连一条容量为2(因为要来回),费用为0的边 n到汇点连一条容量为2,费用为0的边 另外的就是题目中输入的了 另 ...
- Mac Dropbox 文件不显示同步图标 解决
前言 开始时关了这个功能,今天想打开发现怎么也恢复不了. 按照官方教程说的重装也无济于事.最后在官方BBS发现一篇帖子顺利解决了问题 解决方案 这哥们意思是说禁用了一个Finder的插件就好了(有意思 ...
- ZBrush 4R7中自定义笔刷
为了便于雕刻,ZBrush®很人性化地设计了自定义笔刷.随着ZBrush软件版本不断更新,功能也在不断完善.只是在笔刷面板ZBrush软件就为用户提供了上百种之多,如果我们想要用某种笔刷,一个个找起来 ...
- div纵向居中的方法(转载)
方法一这个方法把一些 div 的显示方式设置为表格,因此我们可以使用表格的 vertical-align property 属性. <div id="wrapper"> ...