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" ...
随机推荐
- 关于PHP程序员技术职业生涯规划 2017年3月5日韩 天峰
看到很多PHP程序员职业规划的文章,都是直接上来就提Linux.PHP.MySQL.Nginx.Redis.Memcache.jQuery这些,然后就直接上手搭环境.做项目,中级就是学习各种PHP框架 ...
- thread库,附带程序介绍
千万注意线程不要比主线程晚结束,主线程一旦结束,对象将被销毁 std:thread 代表了一个线程对象 this_thread:是一个命名空间,对当前调用者线程进行操作 如果把可调用对象作为参数传递给 ...
- 转录组的组装Stingtie和Cufflinks
转录组的组装Stingtie和Cufflinks Posted: 十月 18, 2017 Under: Transcriptomics By Kai no Comments 首先这两款软件都是用 ...
- css 需要阴影的效果
box-shadow: 0 0 10px 10px #b9bcbf; CSS3 box-shadow 属性 CSS 参考手册 实例 向 div 元素添加 box-shadow: div { box-s ...
- 最新Dashboard设计实例、技巧和资源集锦,视觉和功能两不误,妥妥的!
Dashboard设计,尽管设计师们叫法各不相同(例如:“数据面板设计”, “控制面板设计”, “仪表盘设计”或“后台界面设计”等等).但,此类设计的最终目都是力求以最直观.最简洁的方式呈现各种信息和 ...
- maven clean package 时出现Failed to read artifact descriptor for的问题解决
maven clean package 时出现Failed to read artifact descriptor for的问题 [ERROR] Failed to execute goal on p ...
- 简单rmi示例
User类 注意:需要实现序列化 package study.rmi.server; import java.io.Serializable; public class User i ...
- PHP filter 函数FILTER_CALLBACK 过滤数据
<?php function convertSpace($string) { return str_replace(" ", "_", $string); ...
- 2019.02.07 bzoj4784: [Zjoi2017]仙人掌(仙人掌+树形dp)
传送门 题意:给一个无向连通图,问给它加边形成仙人掌的方案数. 思路: 先考虑给一棵树加边形成仙人掌的方案数. 这个显然可以做树形dp. fif_ifi表示把iii为根的子树加边形成仙人掌的方案数. ...
- java正则表达式笔记
import java.util.regex.Matcher; import java.util.regex.Pattern; import java.util.regex.PatternSyntax ...