Reorder the Books HDU - 5500
2016-12-17 20:53
435 查看
题意:
书号从上到下,从大到小。每次只能移动一本书。问最少移动几次可以还原
思路:
拿到最大的书开始往上找是否存在次大的。
书号从上到下,从大到小。每次只能移动一本书。问最少移动几次可以还原
思路:
拿到最大的书开始往上找是否存在次大的。
#include <iostream> #include <stdio.h> #include <cstring> #include <algorithm> #include <queue> #define maxn 200005 using namespace std ; int a[maxn]; int main() { int T; cin>>T; for(int Case=1;Case<=T;Case++) { int n,pos; cin>>n; for(int i=1;i<=n;i++) { cin>>a[i]; if(a[i]==n) { pos=i; } } int ans=0; ans=n-pos; int need=n-1; for(int i=pos-1;i>=1;i--) { if(a[i]==need) { need--; } else { ans++; } } cout<<ans<<endl; } return 0; }
相关文章推荐
- HDU 5500 Reorder the Books(O(n)的复杂度就够了)——BestCoder Round #59(div.1 div.2)
- 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(模拟)
- HDU 5500 Reorder the Books(思维题,很巧妙)
- hdu 5500 Reorder the Books 【BestCoder Round #59 (div.2) 第二题】
- 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