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

又wa 又 re 到最后 ac.给后来者分享一点教训

Posted by denghongchao at 2009-08-04 12:23:44 on Problem 1107
wa 是因为没有考虑 k1,k2,k3 rotate过头的情况。
re 是因为 ki %= top 时要考虑 top 为 0 的情况。
附核心代码:
        ts = "";   top = 0;
        for(int i = 0 ;i < len;++i){
            if(a[i]>='a' && a[i] <='i'){
                pos[top] = op[top] = i;
                ++top;
            }
        }
        if(top != 0){
        k1 %= top;
        for(int i = top - k1;i < top;++i)
            ttt[i - top + k1] = pos[i];
        for(int i = top-1 ;i >= k1;--i)
            pos[i] = pos[i-k1];
        for(int i = 0 ;i<k1;++i)
            pos[i] = ttt[i];
        for(int i = 0 ;i < top;++i)
            ts += a[pos[i]];
        for(int i = 0 ;i< top;++i)
            a[op[i]] = ts[i];
        }

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