Test instructions
There are n books, numbered 1~n, now the order of the book is disorderly, the need to return to an orderly appearance, each time can only draw one of the first and inserted in the front, ask how many times the minimum number of smoke?
Ideas:
If Pos[i] is not the book I, then all the books on the right of book I must be drawn out. The drawn book must be able to return to its final position, that is, each book is drawn up to 1 times, you can imagine out of the direct throw away, in the rest of the book to find an orderly, and the last element is N, and the linear 1 of the sequence {... n-2,n-1,n}.
1 //#include <bits/stdc++.h>2#include <iostream>3#include <cstdio>4#include <cstring>5#include <cmath>6#include <Set>7#include <deque>8#include <map>9#include <algorithm>Ten#include <vector> One#include <iostream> A #definePII pair<int,int> - #defineBack Que[rear-1] - #defineINF 0x7f7f7f7f the #defineLL Long Long - #defineULL unsigned long Long - using namespacestd; - Const DoublePI = ACOs (-1.0); + Const intn= -; - + intN, A[n]; A intcal () at { - for(intI=n; I>0; i--) - if(a[i]==n) n--; - returnN; - } - in intMain () - { to //freopen ("Input.txt", "R", stdin); + intT;cin>>T; - while(t--) the { *scanf"%d",&n); $ for(intI=1; i<=n; i++)Panax Notoginsengscanf"%d", &a[i]); -Cout<<cal () <<Endl; the } + return 0; A}
AC Code
HDU 5500 Reorder The Books (water problem)