码迷,mamicode.com
首页 > 其他好文 > 详细

繁华模拟赛 摆书

时间:2016-09-15 17:51:52      阅读:88      评论:0      收藏:0      [点我收藏+]

标签:

 技术分享

技术分享

 

技术分享

技术分享

#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")))

 

繁华模拟赛 摆书

标签:

原文地址:http://www.cnblogs.com/hyfer/p/5875117.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!