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

很简单的,为什么会MLE,帮忙指正,无限感激!

Posted by 6729763 at 2011-04-19 09:33:16
题目:http://acm.nankai.edu.cn/p1703.html

我用的内存也不多啊,就是一个队列,长度小于30,还有一个数组a[maxsize<=30]

我的代码:

#include <cstdlib>
#include <iostream>
#include<queue>
using namespace std;

int main(int argc, char *argv[])
{
    int maxsize;
    queue<int> q;
    int num;
    char ch;
    int icnt = 1;
    while(1)
    {
         cin>>num;
         q.push(num);
         if(num>maxsize)
             maxsize = num;
         ch = cin.get();
         if(ch==EOF)
         break;        
    }
    long *a = new long[maxsize];
    for(int i = 0; i<maxsize; i++)
    {a[i] = 0;}
    a[0] = a[1] = 1;
    for(int i = 2; i<maxsize; i++)
    {
         for(int j = 0; j<i; j++)
         {
             a[i] += a[j]*a[i-1-j];           
         }
                 
    }
    while(!q.empty())
    {
         cout<<"Case "<<icnt<<":"<<endl;
         cout<<a[q.front()]<<endl;
         icnt++;
         q.pop();                 
    }
    delete []a;
    //system("PAUSE");
    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