HDU 5500 Reorder the Books

宏杉MacroSan存储开局指导-流程 目录 1. 导入ODSP授权 2.1.版本确认 2.2.存储设备升级U盘、升级光盘制作方法 开局流程如下: 1. 导入ODSP授权 ODSP授权文件随设备附带,拆箱可见 2.1.版本确认 java模式 html模式 2.2.存储设备升级U盘、升级光盘制作方法 准备工具 空白U盘: 1个,容量要求大于等于4GB。仅制作升级U盘时需要。 制作升级U盘步骤 1.将U盘插入PC机USB口,保证PC机能识别到U盘。 2.运行UltraISO,选择菜单中的 文件-&g... 阅读详情

Reorder the Books

Time Li: 4000/2000 MS (Java/Others)    Memory Limit: 131072/131072 K (Java/Others)
Total Submission(s): 1428    Accepted Submission(s): 752


Problem Description
dxy has a collection of a series of books called "The 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.
 

Input
There are several testcases.

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.
 

Output
For each testcase,output one line for an integer standing for the minimum steps Evensgn would use to reorder the books.
 

Sample Input
  
2 4 4 1 2 3 5 1 2 3 4 5
 

Sample Output
  
3 0
 

Source
 
题意是从下面拿出来放顶上,最少拿多少次能变成原序
考虑现有序列里那些是不用拿的,最大的不用拿,第二大的如果在他后面,那么肯定先把这个那顶上,然后在依次拿,最少n-1,如果在他前面,那么也不需要拿,第三大 的如果在第二大的前面也不需要拿,否则最少n-2,,依次类推。。。。可以看出我们只需要从后往前找有多少个不需要拿的即可


#include<stdio.h>
int main()
{
	int a,t,n,i,ji,num[1000];
	scanf("%d",&t);
	while(t--)
	{
		scanf("%d",&n);
		ji=0,a=n;
		for(i=0;i<n;i++)
		scanf("%d",&num[i]);
		for(i=n-1;i>=0;i--)
		{
			if(num[i]==a)
			{
				a--;
				ji++;
			}
		}
		printf("%d\n",n-ji);
	}
	
}






RouterOS网桥VLAN实战:从零构建安全隔离的二层虚拟网络 本文详细讲解了如何在RouterOS上利用网桥和VLAN功能,从零开始构建安全隔离的二层虚拟网络。通过分步实战演示,涵盖核心概念、网桥创建、PVID设置、VLAN规则配置及安全过滤,帮助网络管理员实现办公、访客与服务器网络的逻辑隔离与灵活管理,提升网络安全性。 阅读详情

相关推荐

新手网工别慌!手把手带你搞定华为OLT开局配置(从登录到业务下发全流程)

本文为新手网络工程师提供华为OLT设备开局配置的详细指南,涵盖从设备登录、基础配置到业务部署的全流程。通过实战案例和常见问题排查,帮助读者快速掌握华为OLT配置技巧,确保业务顺利开通。

weixin_33721344的博客 495

HDU 5500(Reorder the books)

                                       Reorder the Books                       Time Limit: 4000/2000 MS (Java/Others)    Memory Limit: 131072/131072 K (Java/Others)                                   ...

snayf的博客 317

LTspice仿真三线制PT100高精度测温系统设计

本文详细介绍了如何使用LTspice仿真设计三线制PT100高精度测温系统。文章从三线制原理出发,逐步讲解了在LTspice中建模PT100、构建惠斯通电桥进行信号转换、设计差分放大与滤波电路、选型ADC以及进行系统联调与误差分析的全过程,旨在帮助工程师实现0.5°C分辨率的工业测温方案设计。

pz89012345的博客 102

hdu 5500 Reorder the Books

Reorder the Books Time Limit: 4000/2000 MS (Java/Others)    Memory Limit: 131072/131072 K (Java/Others) Total Submission(s): 463    Accepted Submission(s): 302 Problem Description dxy has

Jinming Su 467

VMware VSAN 高级参数介绍(测试用)

VSAN 的策略驱动让我们看到了VSAN无穷的潜力,其设计思路相当新颖,在一个基础资源池上使用策略就能实现不同对象的区分服务,而目前没有其他厂家能到VMware这样的高度。 VSAN 呈现给用户配置很简单,但实际上设计及后台比较复杂。笔者无意间发现了VSAN的隐藏高级参数设置,有很多好玩的选项想分享出来。这些参数全部是针对每主机进行设置的。VSAN 中有很多默认设置,这些设置应该都是研发人员多次测试得出的最优值,修改可能导致环境异常,并不建议修改! 目录 参数1:全闪配置下 SSD 写缓存最大.

山水牧羊 2037

国产化办公新选择:在银河麒麟V10上部署ToDesk远程桌面

本文详细介绍了在国产操作系统银河麒麟V10上部署ToDesk远程桌面的完整指南。作为国产远程控制工具,ToDesk在连接速度、系统适配性和用户体验方面表现优异,特别适合国产化办公场景。文章包含X86和ARM架构的安装步骤、常见问题排查及性能优化技巧,帮助用户高效实现远程办公。

weixin_33742618的博客 241

HDU 5500 Reorder the Books

详细代码自己找自己敲,以下会不定时更新。一个文件中只能有一个公共类 java的继承只能是单继承。一个类之所以能够调用父类成员,是由于java编译器会自动为子类添加一个引用名为super的父类成员对象。创建子类对象的过程就是从底层的基类往上,一层层地来调用构造方法。如果调用父类的有参构造方法,需要用到super关键字。多态: 多态具体表现在重写和重载 多态就是类的多种表现方式 比如同名不同参

仰望星空 542

从DC到DCG:手把手教你搭建物理感知综合流程(含DEF文件处理避坑指南)

本文详细介绍了从Design Compiler(DC)过渡到DC Topographical(DCT)和DC Graphical(DCG)的完整操作框架,特别针对DEF文件处理提供避坑方案。通过环境准备、工具升级、DEF文件处理、DCG综合配置等步骤,帮助开发者高效应对28nm以下工艺节点的物理感知综合挑战,显著提升时序收敛效率。

weixin_27966471的博客 386

hdu 5500 Reorder the Books 【BestCoder Round #59 (div.2) 第二题】

Reorder the Books Time Limit: 4000/2000 MS (Java/Others)Memory Limit: 131072/131072 K (Java/Others) Total Submission(s): 244Accepted Submission(s): 168 Problem Descript...

weixin_33831196的博客 174

PostgreSQL:Patroni 高可用架构,基于etcd的自动故障转移集群

本文详细介绍了基于Patroni和etcd构建PostgreSQL高可用集群的方案。Patroni作为外部守护进程,通过etcd分布式协调服务实现自动故障转移、主节点选举等关键功能,弥补了PostgreSQL原生缺乏自动故障转移的不足。文章涵盖核心架构(3节点PG+3节点etcd)、环境规划、etcd集群部署(包括配置验证)以及Patroni安装配置的关键步骤,特别强调了Patroni自动初始化PG实例、配置同步复制等生产级特性。该方案通过外部组件协同工作,在不修改PG源码的情况下实现了生产环境所需的高可用

数据知道的博客 2506

SAP BW/4HANA 项目字段级数据血缘分析的方法与工具

利用SAP自带工具可以在一定程度上查看数据流和字段使用情况,但往往需要人工逐步深挖。适用于简单场景或验证单个字段的映射。借助SAP数据治理解决方案(如 Information Steward、Data Intelligence 等)能够自动整合元数据,提供图形化、跨系统的血缘分析,适合对数据 lineage 有严格要求的企业级项目。第三方工具则提供了灵活强大的功能,如自动文档、生成功能丰富的报告,对于复杂环境下的血缘分析和影响分析非常有帮助。自行开发SQL/CDS脚本。

2007 年 ~ 2025 年,深耕 SAP 技术 18 年 479

HDU5500 Reorder the Books 规律题

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): 1823    Accepted ...

lanshan1111的博客 219

《信息化项目文档模板十二——业务需求新增/变更审批确认表 》

系列文章目录 《信息化项目文档模板一——项目需求说明书》 《信息化项目文档模板二——项目启动会文档模板》 《信息化项目文档模板三——会议纪要模板》 《信息化项目文档模板四——系统项目蓝图设计模板》 《信息化项目文档模板五——系统详细设计模板》 《信息化项目文档模板六——系统详细设计模板》 《信息化项目文档模板七——系统开发计划模板》 《信息化项目文档模板八——系统功能测试模板》 《信息化项目文档模板九——系统压力测试模板》 《信息化项目文档模板十——系统推广上线计划模板》 《信息化项目文档模板十一——系统用

商务合作|问题讨论|交流学习 请联系作者微信,加微信请务必注明来意,博客主页有联系方式 1715

hdu 5500 Reorder the Books(贪心)

题目链接:hdu 5500 Reorder the Books代码#include <cstdio> #include <cstring> #include <algorithm>using namespace std; const int maxn = 30;int N, A[maxn];int main () { int cas; scanf("%d", &cas); w

不慌不忙、不急不躁 799

Statistics and Machine Learning Toolbox

Statistics and Machine Learning Toolbox(带书签),MATLAB统计学习工具

VB摄像头监控

该VB模块可对摄像头捕获的画面进行录像等,可在创建的窗口进行控制

HDU 5500 Reorder the Books【思维】

题目: dxy has a collection of a series of books called "The Stories of SDOI",There are n(n≤19)n(n≤19) books in this series.Every book has a number from 11 to nn.  dxy puts these books in a book stack ...

二喵君的博客 246

计算机控制技术及应用

《计算机控制技术及应用》通过总结作者的科研成果和吸收国内外的先进理论、方法和技术,以计算机控制系统的网络化、开放化、智能化和集成化发展趋势为主线索,主要介绍计算机控制系统的基本概念和计算机控制系统的典型形式,计算机控制系统的数学描述与基本分析方法,以及数字PID控制器、最少拍控制系统、达林算法、状态变量设计法等设计方法及其各种改进算法。重点突出计算机控制系统输入输出通道接口的设计方法和典型控制系统的设计案例与实现方法等。

hdu5500 Reorder the Books 贪心

题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=5500 思路:问题等价为,一个1~n组成的序列,每次从中取出一个数,插到最前面,用最少的步骤使序列变为升序。其实在整个操作过程中,我们只需要保持相对顺序即可。每次操作保证pos[i - 1] < pos[i],即:i - 1出现在i的前面。如:首先检查n - 1是否出现在n前面,不是的话将n - 1移

ww32cc的博客 488

精雕软件(JDpaint) 5.5 绿色版

精雕软件(JDpaint) 5.5 绿色版精雕软件(JDpaint) 5.5 绿色版精雕软件(JDpaint) 5.5 绿色版

hdu 5500 Reorder the Books

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): 942Accepted Sub...

deyou1988的专栏 164

hdu 5500 Reorder the books

题目: 给定一个从1到n的乱序序列,每次取一个数到最前面,问最少多少次能使序列变为增序。 初始以为是逆序数,后来知道不对,应该是贪心。 细想发现,加入操作了大小等于k的数,那么所有小于k的数也都得操作。首先最大的数n是不用操作的(其他数操作好了,n自然在最后面了)。先找到数n的位置,在n之前找n-1,若没找到n-1,则n-1需要操作,所有小于n-1的数均需要操作;若找到了n-1,再接着往前依

journey_fan的专栏 1190

hdu 5500 Reorder the books 思维

Reorder the Books Time Limit: 4000/2000 MS (Java/Others)Memory Limit: 131072/131072 K (Java/Others) Total Submission(s): 1822Accepted Submission(s): 937 Problem Description dxy has a coll...

pxlsdz的博客 510

HDU 5500 Reorder the Books (规律)

Reorder the BooksTime Limit: 4000/2000 MS (Java/Others) Memory Limit: 131072/131072 K (Java/Others) Total Submission(s): 1416 Accepted Submission(s): 742Problem Description dxy has a collection

=_= 398

Reorder the Books(HDU-5500)

Problem Description dxy has a collection of a series of books called "The Stories of SDOI",There aren(n≤19)books in this series.Every book has a number from1ton. dxy puts these books in a book...

Alex_McAvoy的博客 347

hdu-5500 Reorder the Books

Reorder the Books Time Limit: 4000/2000 MS (Java/Others) Memory Limit: 131072/131072 K (Java/Others) Total Submission(s): 1834 Accepted Submission(s): 949 Problem Description dxy has a collectio...

FreeGo~ 187

HDU 5500 - Reorder the Books(模拟)

Reorder the BooksTime Limit: 4000/2000 MS (Java/Others) Memory Limit: 131072/131072 K (Java/Others) Total Submission(s): 1432 Accepted Submission(s): 755Problem Description dxy has a collection

Snakeflute的博客 329

HDU 5500 Reorder the Books思维题

dxy has a collection of a series of books called “The 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 o...

qq_26139541的博客 182

HDU_5500 Reorder the Books

http://acm.hdu.edu.cn/showproblem.php?pid=5500 题意:给定一个从1到n的乱序序列,每次取一个数到最前面,问最少多少次能使序列变为增序。 思路:首先最大的数n是不用操作的(其他数操作好了,n自然在最后面了)。先找到数n的位置,在n之前找n-1,若没找到n-1,则n-1需要操作,所有小于n-1的数均需要操作;若找到了n-1,再接着往前依次找n-2,

老子(道家) 439
上一篇: HDU 5744 Keep On Movin// 2016 Multi-University Training Contest 2
下一篇: POJ 1703 Find them, Catch them
jerans
博客等级 码龄10年 54粉丝 255原创
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

个

红包个数最小为10个

元

红包金额最低5元

当前余额3.43元 前往充值 >
需支付:10.00元
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付元
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值