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

此题为什么同样的代码:用C++交是TLE,但用G++交却0ms AC...

Posted by asdf_1234 at 2010-06-19 21:31:57 on Problem 3125
//C++ TLE
//G++ 0ms AC
#include <iostream>
#include <cstdio>
#include <deque>

using namespace std;

typedef struct nd {
    int p;
    bool goal;
    nd(int _p,bool _goal):p(_p),goal(_goal) {
    }
} node;

int main() {
    int t,n,m,pi,r;
    scanf("%d",&t);
    while (t--) {
        r=0;
        deque<node> p;
        scanf("%d %d",&n,&m);
        for (int i=0; i<n; i++) {
            scanf("%d",&pi);
            if (i==m)
                p.push_back(node(pi,true));
            else
                p.push_back(node(pi,false));
        }
        bool goalP=false;
        while (!goalP) {
            int pmax=p[1].p;
            for (unsigned int i=2; i<p.size(); i++)
                if (p[i].p>pmax)
                    pmax=p[i].p;
            node p0=p[0];
            p.pop_front();
            if (pmax>p0.p) {
                p.push_back(p0);
            } else {
                r++;
                if (p0.goal)
                    goalP=true;
            }
        }
        printf("%d\n",r);
    }
    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