HDU 5500 Reorder The Books (water problem)

Source: Internet
Author: User

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)

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.