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

Re:我的算法已经O(n)了,为什么还刷不到0ms,还有什么改进地方吗

Posted by plumstar at 2007-10-08 20:51:50 on Problem 1363 and last updated at 2007-10-08 20:52:19
In Reply To:Re:我的算法已经O(n)了,为什么还刷不到0ms,还有什么改进地方吗 Posted by:00648155 at 2007-10-08 20:02:37
> 试这个数据
> 5
> 1 4 5 2 3
> 0
> 0
Output
No
有什么问题么?
俺的程序:
#include <stdio.h>
#include <stdlib.h>

struct list
{
    int data;
    struct list * nextPtr;
};
typedef struct list *listNode;

void insert(listNode *sPtr, int value)
{
    listNode newPtr;
    newPtr = (listNode)malloc(sizeof(listNode));
    newPtr->data = value;
    newPtr->nextPtr = *sPtr;
    *sPtr = newPtr;
}
int main()
{
    listNode startPtr = NULL;
    int number, *value, i, mark;

    while ((scanf("%d", &number)) == 1 && number != 0)
    {
        value = (int *)malloc(sizeof(int)*number);
        while ((scanf("%d", &value[0])) && value[0] != 0)
        {
            for (i = 1; i < number; i ++)
                scanf("%d", &value[i]);
            mark = number;
            i = number - 1;
            while (mark)
            {
                insert(&startPtr, value[i]);
                while (startPtr != NULL && startPtr->data == mark)
                {
                    startPtr = startPtr->nextPtr;
                    mark --;
                }
                i --;
                if (i == -1)
                    break;
            }
            if (mark == 0)
                printf("Yes\n");
            else
                printf("No\n");
        }
        printf("\n");
        free(value);
    }

    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