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

错了几次,居然忘了将a可以为0考虑进去

Posted by pqr657017034 at 2009-10-23 11:18:02 on Problem 2533
#include <iostream>
using namespace std;
int* b;
int maxlist(int n)
{
    const int N = n;
    int k = 0,i = 0,j = 0,a;
    b = new int[N + 1];
    b[0] = -1;
    for(i = 0;i < N;i++)
    {
        cin >> a;
        if(a > b[k])
            b[++k] = a;
        else if(a < b[k])
        {
            for(j = k - 1;a <= b[j];j--);
            b[j + 1] = a;           
        }
    }
    delete[] b;
    return k;
}        
int main()
{    
    int n;
    while(cin >> n)    
        cout << maxlist(n) << endl;      
    return 0;
}
一开始我将b【0】初始化为0,结果将a=0的情况没算进去,改为-1后,终于AC了

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