Online JudgeProblem SetAuthorsOnline ContestsUser
Web Board
Home Page
F.A.Qs
Statistical Charts
Problems
Submit Problem
Online Status
Prob.ID:
Register
Update your info
Authors ranklist
Current Contest
Past Contests
Scheduled Contests
Award Contest
User ID:
Password:
  Register

没有天理了!改一个const就0ms之前无限tle

Posted by Yt_zp at 2015-08-18 18:40:02 on Problem 3125
之前没用const int maxn 每次都是直接除100
简直了 谁呢告诉我这是为什么!!!
#include <iostream>
#include <cstdio>
#include <cstring>
using namespace std;
const int maxn=102;
inline int aabs(int a){
    return a<0?-a:a;
}
int a[maxn],st,ed;
int main(){
    int loop;
    scanf("%d",&loop);
    while(loop--){
        int num,pos;
        scanf("%d %d",&num,&pos);
        for(int i=0;i<num;++i)scanf("%d",&a[i]);
        a[pos]=-a[pos];
        st=0;
        ed=num;
        int cns=0;
        while((ed+1)%maxn!=st){
            int k=a[st];
            st=(st+1)%maxn;
            bool flag=true;
            for(int i=st;i!=ed;i=(i+1)%maxn)
                if(aabs(a[i])>aabs(k)){
                    flag=false;
                    a[ed]=k;
                    ed=(ed+1)%maxn;
                    break;
                }
                if(flag){
                    cns++;
                    if(k<0){
                        printf("%d\n",cns);
                        break;
                    }
                }
            }
    }
    return 0;
}

Followed by:

Post your reply here:
User ID:
Password:
Title:

Content:

Home Page   Go Back  To top


All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator