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

这两个代码有什么不同?为什么一个AC,一个TLE。。。

Posted by SheepArmy at 2011-03-30 16:27:49 on Problem 2867
--------------TLE-----------------------
#include <cstdio>
#include <cstring>

using namespace std;

const int maxN = 51200;

int data[maxN];
int index[maxN];

int main()
{
    int cas = 0;
    int ng, nr, nq;

    while(scanf("%d", &ng) != EOF && ng != 0)
    {
        for(int i = 1; i <= ng; i++)
            data[i] = index[i] = i;

        scanf("%d", &nr);
        for(int i = 0; i < nr; i++)
        {
            int s, t;

            scanf("%d %d", &s, &t);
            for(int j = s, k = t; j < k; j++, k--)
            {
                index[data[j]] = k;
                index[data[k]] = j;
                data[j] ^= data[k], data[k] ^= data[j], data[j] ^= data[k];
            }
        }

        printf("Genome %d\n", ++cas);

        scanf("%d", &nq);
        for(int i = 0; i < nq; i++)
        {
            int q;

            scanf("%d", &q);
            printf("%d\n", index[q]);
        }
    }
    return 0;
}

-------------------AC---------------------------

#include <cstdlib>
#include <iostream>

using namespace std;

int main(int argc, char *argv[])
{
    int N,Q,R,gen[50005],r1,r2,sen=1,temp;
    while(scanf("%d",&N),N!=0)
    {                       
       for(int t=1;t<=N;t++)
         gen[t]=t;
       scanf("%d",&R);
       while(R--)
       {
         scanf("%d%d",&r1,&r2);
         while(r1<=r2)
         {
            temp=gen[r1];
            gen[r1]=gen[r2];
            gen[r2]=temp; 
            r1++;
            r2--;
         }       
       }
       scanf("%d",&Q);
       printf("Genome %d\n",sen++);
       while(Q--)
       {
         scanf("%d",&temp);
         int t=1;
         while(gen[t]!=temp)
          t++;
         printf("%d\n",t);        
       }                         
    }
    return EXIT_SUCCESS;
}

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