Reorder the Books -- hdu -- 5500
http://acm.hdu.edu.cn/showproblem.php?pid=5500
Reorder the Books
Time Limit: 4000/2000 MS (Java/Others) Memory Limit: 131072/131072 K (Java/Others)
Total Submission(s): 920 Accepted Submission(s): 502
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.
#include<stdio.h>
#include<string.h>
#define N 110000 int a[N]; int main()
{
int T;
scanf("%d", &T);
while(T--)
{
int n, i;
scanf("%d", &n); memset(a, , sizeof(a));
for(i=; i<n; i++)
scanf("%d", &a[i]); int ans=n, an=; for(i=n-; i>=; i--)
{
if(ans==a[i])
ans--;
else
an++;
}
printf("%d\n", an);
}
return ;
}
Reorder the Books -- hdu -- 5500的更多相关文章
- 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
http://acm.hdu.edu.cn/showproblem.php?pid=5500 Reorder the Books Time Limit: 4000/2000 MS (Java/Othe ...
- 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 ...
- 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)本,每本书有一个编号,从 ...
- hdu 5500 Reorder the Books(规律)
题意: 有一个1→n的排列形成的数列,我们要用最少的操作次数把这个数列从小到大排序,每次操作都是把一个数放到整个数列的最前面. 思路: 首先最大的数n是不用操作的(其他数操作好了,n ...
- HDU 5500 Reorder the Books (水题)
题意: 有n本书,编号为1~n,现在书的顺序乱了,要求恢复成有序的样子,每次只能抽出其中一本并插到最前面,问最少需要多少抽几次? 思路: 如果pos[i]放的不是书i的话,则书i的右边所有的书都必须抽 ...
- Reorder the Books-HDU5500
Problem Description dxy has a collection of a series of books called "The Stories of SDOI" ...
随机推荐
- java的eclipse的使用
1下载eclipse地址:www.eclipse.org/downloads/ 解压就可安装 注意: 这可能你是没有安装java运行环境(jre或jdk) 直接www.java.com,下载就行 下一 ...
- 前端基础之JavaScript day51
前端基础之JavaScript JavaScript概述 JavaScript的历史 1992年Nombas开发出C-minus-minus(C--)的嵌入式脚本语言(最初绑定在CEnvi软件中) ...
- Canvas绘图 (html5新增特性)
Canvas 使用<canvas>对象,需要设置属性:width,height.指定绘图的区域大小.在canvas标签前后出现的信息将在不支持<canvas>元素的浏览器中显示 ...
- JVM 类加载器 (二)
1.类加载器(ClassLoader)负责加载class文件,class文件在文件开头有特定的文件标识,并且ClassLoader只负责 class 文件的加载,至于class文件是否能够运行则由Ex ...
- SQL注入漏洞的原理
在平常生活中,我们登陆某网页,常常需要输入用户名和密码,点击登陆,即可登陆成功. 对于黑客来说,不需要用户名和密码,只输入 admin '— 也可以登陆成功. 黑客利用的这种漏洞就是SQL Injec ...
- BZOJ1228或洛谷2148 [SDOI2009]E&D
BZOJ原题链接 洛谷原题链接 完全不会呀.. 写了这题才知道\(SG\)函数原来也能打表找规律... 题解请看大佬的博客 #include<cstdio> using namespace ...
- ES6 中 let and const
let 和 const 命令 let 命令 基本用法 ES6 新增了let命令,用来声明变量.它的用法类似于var,但是所声明的变量,只在let命令所在的代码块内有效. { let a = 10; v ...
- [Jmeter] Run Command to generate a specific listener’s chart report
Run Command to generate a specific listener’s chart report: Download cmdrunner-2.0.jar : https://jme ...
- fastcgi vc6.0demo
#include <WinSock2.h> #include <stdio.h> #pragma comment(lib, "ws2_32.lib") ty ...
- Java第15章笔记
字符串的概述 1.什么是字符串:零个或多个字符组成的有限序列 2.如何使用字符串:(使用字符串分为两步) 1)定义并初始化字符串 2)使用字符,对字符串进行一些处理 ...