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)完成的

Posted by lincc at 2008-10-03 12:52:23 on Problem 1007
In Reply To:算逆序数可以O(n)完成的 Posted by:nightelf at 2007-08-28 12:35:42
> int count_inver(char *str, int len)
> {
>         int i;  
>         int cnt = 0;
>         int a[4] = {0};
>         for(i = len - 1; i >= 0; i--) {
>                 switch (str[i]) {
>                         case 'A':
>                                 a[1]++; 
>                                 a[2]++; 
>                                 a[3]++; 
>                                 break;  
>                         case 'C':
>                                 a[2]++; 
>                                 a[3]++; 
>                                 cnt += a[1];
>                                 break;  
>                         case 'G':
>                                 a[3]++; 
>                                 cnt += a[2];
>                                 break;  
>                         case 'T':
>                                 cnt += a[3];
>                 }
>         }
>         return cnt;
> }

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