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)本,每本书有一个编号,从 ...
随机推荐
- 2015.05.12,外语,读书笔记-《Word Power Made Easy》 15 “如何谈论不同人的特点” SESSION 45
TEASER PREVIEW 以-ous结尾的,描绘某人特点的词语包括: fawning(['fɔ:niŋ] adj.奉承的),servilely(['sә:vail] adj. 卑屈的, 奴隶的) ...
- mysql_udf_http(根据mysql表自动触发发送http请求)
下载 tar包wget http://mysql-udf-http.googlecode.com/files/mysql-udf-http-1.0.tar.gz解压tar -vzxf mysql-ud ...
- redis的windows版本下载地址及windows的客户端工具
源码:https://github.com/MSOpenTech/redis 安装包:https://github.com/MSOpenTech/redis/releases 客户端工具:https: ...
- 爬虫概念与编程学习之如何爬取视频网站页面(用HttpClient)(二)
先看,前一期博客,理清好思路. 爬虫概念与编程学习之如何爬取网页源代码(一) 不多说,直接上代码. 编写代码 运行 <!DOCTYPE html><html><head& ...
- 小白向:web中利用request.getPart()上传文件到服务器
被文件上传弄得焦头烂额的一天,果然web中的路径和各种设置真的好讨厌= = 下面是超级小白的.及其简约的“详”解 1.明确目的: 用户将 1.txt 文件 上传到 服务器(web工程下的某个文件夹)中 ...
- solarwind之network Atlas
1. 连接密码为空,连接到Orion 2. 连接后如下图 3. 直接拖动节点即可进行绘制地图 4. 查看它的相关属性
- iOS开发-测量APP启动耗时
冷启动 冷启动就是App被kill掉以后一切从头开始启动的过程. 热启动 当用户按下home键的时候,iOS的App并不会马上被kill掉,还会继续存活若干时间.理想情况下,用户点击App的图标再次回 ...
- C++下面关于字符串数组的一些操作
今天在写一个搜索引擎的分词系统,是很简单的那种,但是居然费了我一天的时间还没完成,晚上估计还得弄一会了,但是在这个过程中,遇到了集中关于字符串数组的操作,值得和大家分享一下. 首先是关于统计字符串数组 ...
- 初见UDP_Server
from socket import *ip_prot = ('192.168.55.1',8080)buffer_size = 1024udp_sever = socket(AF_INET,SOCK ...
- [CTSC1999][网络流24题]家园
题目:洛谷P2754. 题目大意:有$n$个空间站,$m$个飞船,每个飞船有各自的停靠站点,并且从第一个停靠站点开始,不断循环.每个飞船有不同的容量(-1为月球,0为地球).每个飞船初始停在第一个停靠 ...