HDU
来源:互联网 发布:windows redis集群搭建 编辑:程序博客网 时间:2024/05/01 10:11
最右策略就是从前面找最大的往后移
就看大的在前面的个数,相当于一个指针从后往前找,同时记录位置和当前位置应该出现的值
#include <iostream>#include <cstdio>#include <cstring>#include <cstdlib>#include <cmath>#include <set>#include <queue>#include <algorithm>#include <vector>#include <cctype>#include <stack>#include <sstream>#include <list>#include <map>#include <assert.h>#define debug() puts("************")#define MS(a,b) memset(a,b,sizeof a)using namespace std;typedef long long ll;const int maxn = 1000000+7;int T, n;ll a[maxn], b[maxn];int main(){ ios::sync_with_stdio(0); int T; cin>>T; int kase = 1; while(T--) { int n; cin>>n; for (int i = 0; i < n; ++i) { cin >> a[i]; } int ans = 0, t = n, id = n-1; while(1) { if(a[id] == t) { id--; t--; } else if(t > a[id]) { ans++; t--; } else if(t < a[id]) { id--; } if(id < 0 || t == 1) break; } cout << "Case #" << kase++ << ": " << (ans) << endl ; }}