HDU Reorder the Books (数学题吧)
来源:互联网 发布:双色球大赢家缩水软件 编辑:程序博客网 时间:2024/05/19 23:57
问题描述
dxy家收藏了一套书,这套书叫《SDOI故事集》,《SDOI故事集》有n(n≤19)本,每本书有一个编号,从1号到n号。dxy把这些书按编号从小到大,从上往下摞成一摞。dxy对这套书极其重视,不允许任何人动这套书。有一天Evensgn到dxy家玩,dxy因为和妹子有约会,就让Evensgn自己待在他家。Evensgn对这套书非常好奇,偷偷的看了一下,结果发现这里面竟然有当年小E和小Q的故事。Evensgn看得出神,结果把一摞书的顺序打乱了。眼看着dxy就要回来了,Evensgn需要尽快把这摞书恢复到原先排好序的状态。由于每本书都非常重,所以Evensgn能做的操作只有把一本书从书堆中抽出来,然后把这本书放到书堆的顶部。给你打乱的书的顺序,你能帮Evensgn算算最少需要几次上述的操作,他才能把这套书恢复顺序?假如你能算出来的话,Evensgn答应送给你一本他签名的书《SDOI故事集9:小E的故事》
输入描述
输入包含多组数据。第一行包含一个正整数T(T≤30)表示数据组数。对于每组数据,第一行为一个正整数n表示这套《SDOI故事集》中有多少本书。接下来一行n个用空格分开的正整数,表示Evensgn打乱后的这摞书的书号顺序(从上往下)。
输出描述
对于每组数据,输出一行一个整数,表示Evensgn最少需要几次操作才能讲书恢复顺序。
输入样例
244 1 2 351 2 3 4 5
输出样例
30
Hint
对于第一组数据,我们先把3号书放到最上面,接着操作2号书,最后操作1号书,(4,1,2,3)→(3,4,1,2)→(2,3,4,1)→(1,2,3,4),这样就有序了对于第二组数据,这摞书本来就有序了,所以不需要任何操作n>15的数据不超过10组
相对位置计算。。。。脑洞题- - 这种水题竟然没有a掉!!!!!!!!!!!! 太弱了
#include<iostream>#include<cstdio>#include<cstring>using namespace std;int main(){int n,a[30],book[30],t,i,j;int _;cin>>_;while(_--) {cin>>n;for(i=1;i<=n;i++) {cin>>a[i];if(a[i]==n) t=i;}n--;for(i=t-1;i>=1;i--) {if(a[i]==n) n--;}cout<<n<<endl;}return 0;}
0 0
- HDU Reorder the Books (数学题吧)
- HDU Reorder the Books
- HDU 5500 Reorder the Books(模拟)
- HDU 5500 Reorder the Books (规律)
- HDU 5500 Reorder the Books
- HDU 5500 Reorder the Books
- hdu 5500 Reorder the books
- hdu 5500 Reorder the Books
- HDU 5500 Reorder the Books
- hdu 5500 Reorder the Books
- HDU 5500 Reorder the Books
- Reorder the Books HDU - 5500
- HDU 5500 Reorder the Books
- HDU 5500 Reorder the Books
- Reorder the Books(模拟)
- hdu 5500 Reorder the Books(规律题)
- HDU 5500 Reorder the Books(思维题,很巧妙)
- HDU 5500 Reorder the Books(贪心+思维)
- C语言的标识符命名规则
- Codeforces #Round 321 Div2
- light1358 - Fukushima Nuclear Blast【圆与多边形面积的交+二分】
- 网站API自动化测试利器——Postman
- BNUOJ39566 Do use segment tree (树链剖分+维护区间最大连续和)
- HDU Reorder the Books (数学题吧)
- list number of physical RAM in use
- Activity的四种启动模式
- Java对象创建过程
- Boost1.42编译
- 开始学习Python了,每天都要有进步啊
- 应用软件安全
- PostgreSQL+phpPgAdmin总是登录失败(login failed)
- fso对象模型