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:my program seems quite slow then i expected :( , is that any wrong?

Posted by xhope at 2003-11-01 22:14:12 on Problem 1456
In Reply To:first sort by profit, then try whether a product can be arranged Posted by:dynamic at 2003-11-01 20:57:15
// the following is the union set part,
if arrange == 0 , then can't insert any more
if         == -1, can insert (empty)
else  traverse forward to find an empty slot~

path compression is already implemented, 
why still so slow ?

bool insert(int d) {
    if (arrange[d] == 0) return false;
    if (arrange[d] == -1) {
        arrange[d] = d-1;
        return true;
    } else {
        int t = arrange[d];
        while (t > 0 && arrange[t] != -1) {
            t = arrange[t];
        }

        while (d > 0 && d != t) {
            int k = arrange[d];
            arrange[d] = t;
            d = k;
        }
        if (arrange[t] == -1) {
            arrange[t] = t-1;
            return true;
        } else {
            return false;
        }
    }
}

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