Online Judge | Problem Set | Authors | Online Contests | User | ||||||
---|---|---|---|---|---|---|---|---|---|---|
Web Board Home Page F.A.Qs Statistical Charts | Current Contest Past Contests Scheduled Contests Award Contest |
此题为什么同样的代码:用C++交是TLE,但用G++交却0ms AC...//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: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator