繁华模拟赛 摆书

 

 

#include<iostream>
#include<cstdio>
#include<string>
#include<cstring>
#include<algorithm>
using namespace std;
const int maxn = 100005;
int T,n,a[maxn],cnt,ans;
int main(){
    freopen("book.in","r",stdin);
    freopen("book.out","w",stdout);
    cin>>T;
    for(int i = 1;i <= T;i++){
        scanf("%d",&n);
        for(int j = 1;j <= n;j++){
            scanf("%d",&a[j]);
        }
        cnt = n;
        for(int j = n;j >= 1;j--) if(a[j] == cnt) cnt--;
        printf("%d\n",cnt);
    }
    return 0;
} 


#include<cstdio>
#include<iostream>
#include<algorithm>
#include<cstring>
#include<cmath>
#include<vector>
#include<queue>
#include<map>
#include<set>
#include<stack>
#include<cstdlib>
#include<string>
#include<bitset>
#define INF 1000000000
#define N 100005
#define fi first
#define se second
#define debug(x) cout<<#x<<"="<<x<<endl
#define MP(x,y) make_pair(x,y)
using namespace std;
typedef long long LL;
typedef pair<int,int> pii;
int a[N],loc[N];
int main()
{
    int T,n,i;
    freopen("book.in","r",stdin);
    freopen("book.out","w",stdout);
    cin>>T;
    while(T--)
    {
        cin>>n;
        for(i=1;i<=n;i++)
            scanf("%d",&a[i]),loc[a[i]]=i;
        for(i=n;i>1;i--)
            if(loc[i]<=loc[i-1])
                break;
        cout<<i-1<<endl;
    }
    return 0;
}
// davidlee1999WTK 2015/
// srO myk Orz
//ios::sync_with_stdio(false);
//#pragma comment(linker, "/STACK:102400000,102400000")
//#define O2 __attribute__((optimize("-O2")))

 

posted @ 2016-09-15 17:34  ACforever  阅读(202)  评论(0编辑  收藏  举报