关闭

杭电-5500Reorder the Books

标签: 杭电5500Reorder the Books规律
231人阅读 评论(0) 收藏 举报
分类:

Reorder the Books

Time Limit: 4000/2000 MS (Java/Others)    Memory Limit: 131072/131072 K (Java/Others)
Total Submission(s): 935    Accepted Submission(s): 515


Problem Description
dxy has a collection of a series of books called "The Stories of SDOI",There are n(n19) 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(T30) 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



从后往前找找已经排好序的,剩下的都是要移动的

#include<cstdio>
#include<cstring>
#include<algorithm>
using namespace std;
int main()
{
	int a[50],i,m,n;
	scanf("%d",&m);
	while(m--)
	{
		scanf("%d",&n);
		for(i=1;i<=n;i++)
		scanf("%d",&a[i]);
		for(i=n;i>=1;i--)
		{
			if(a[i]==n)
			n--;
		}
		printf("%d\n",n);
	}
	return 0;
 } 




0
0
查看评论
发表评论
* 以上用户言论只代表其个人观点,不代表CSDN网站的观点或立场

杭电题目大致分类

hdu题目大致分类:(详细分类在后)   模拟题, 枚举 1002 1004 1013 1015 1017 1020 1022 1029 1031 1033 1034 1035 1036 103...
  • swanzhu
  • swanzhu
  • 2015-05-23 17:03
  • 1515

杭电oj题库分类

分类一:   基础题:1000、1001、1004、1005、1008、1012、1013、1014、1017、1019、1021、1028、1029、1032、1037、1040、1048、...
  • zwj1452267376
  • zwj1452267376
  • 2014-12-23 21:52
  • 1941

杭电ACM2024java做法

C语言合法标识符 Problem Description 输入一个字符串,判断其是否是C的合法标识符。 Input 输入数据包含多个测试实例,数据的第一行是一个整数n,表示测试实例的个...
  • SuperBeauty
  • SuperBeauty
  • 2015-06-11 10:59
  • 772

杭电acm题目分类 非常详细

按此做成就大神之路:   1002 简单的大数 1003 DP经典问题,最大连续子段和 1004 简单题 1005 找规律(循环点) 1006 感觉有点BT的题,我到现在还没过 1007...
  • lsgqjh
  • lsgqjh
  • 2015-03-13 17:49
  • 8152

【杭电】[2032]杨辉三角

啊 杨辉三角 感觉这一题值得说说杨辉三角是我进入ACM协会时上机做的一题 据当时学长学姐说是当时在所有题里最难的一题 (所以进协会其实还是挺简单的) 做了这一题其它题就不用做了……‘不过这一...
  • u011493189
  • u011493189
  • 2015-12-20 12:00
  • 228

杭电ACM题2000遇到的一点问题

今天做了几个杭电的ACM题,包括2000题,题目描述是:输入三个字符后,按各字符的ASCII码从小到大的顺序输出这三个字符。要求输入为:输入数据有多组,每组占一行,有三个字符组成,之间无空格。输出为:...
  • jeffashan
  • jeffashan
  • 2014-12-02 23:58
  • 1267

杭电ACM——Java版

记录杭电ACM的部分答案,纯手写,如有雷同,算你抄我的。o(∩_∩)o
  • young_kim1
  • young_kim1
  • 2015-04-17 10:29
  • 1907

杭电ACMC语言版答案,持续更新中~

由于一些原因,最近开始刷题,虽然很多人都说是水题,不过对于我这种很久没碰过C语言的来说,每天一水题还是蛮好玩的,虽然网上应该有很多答案啦,我也是本着记下来印象会深刻一点的想法想把它们保存下来,大家勿喷...
  • ChunyuH
  • ChunyuH
  • 2015-08-19 09:58
  • 620

最短路(杭电oj2544)(迪杰斯特拉)

最短路 Time Limit: 5000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others) Total Subm...
  • hdd871532887
  • hdd871532887
  • 2014-12-10 22:53
  • 658

杭电 HDU 1215 七夕节

七夕节 Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others) Total Submis...
  • lsgqjh
  • lsgqjh
  • 2015-04-23 16:33
  • 958
    个人资料
    • 访问:84577次
    • 积分:2206
    • 等级:
    • 排名:第19676名
    • 原创:218篇
    • 转载:3篇
    • 译文:0篇
    • 评论:7条
    最新评论