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

逆序数+基数排序

Posted by avenx at 2012-05-25 16:42:42 on Problem 1007
#include <stdio.h>
#include <math.h>
#include <stdint.h>
#include <string.h>

char data[100][51];
uint16_t record[100][2];
uint16_t cal[1251];
char res[101];

int main()
{
    int n, m;
    int i,j,k;
    int a, g, c, t, inverse;
    int max = 0;

    scanf("%d%d", &m, &n);
    for(i = 0; i < n; i++)
    {
        scanf("%s", data[i]);
        a = 0;
        c = 0;
        g = 0;
        t = 0;
        inverse = 0;

        for(j = m - 1; j >= 0; j--)
        {
            if (data[i][j] == 'A')
            {
                a++;
            }
            else if (data[i][j] == 'C')
            {
                c++;
                inverse = inverse + a;
            }
            else if (data[i][j] == 'G')
            {
                g++;
                inverse = inverse + a + c;
            }
            else if (data[i][j] == 'T')
            {
                t++;
                inverse = inverse + a + c + g;
            }
        }

        record[i][0] = inverse;
        record[i][1] = i;

        if (inverse > max)
            max = inverse;
    }

    memset(cal, 0, 1251);
    for(i = 0; i < n; i++)
        cal[record[i][0]]++;

    for (i = 1; i <= max; i++)    
        cal[i] += cal[i - 1];

    for (i = n - 1; i >= 0; i--)
    {
        res[cal[record[i][0]]] = record[i][1];
        cal[record[i][0]]--;
    }

    for (i = 0; i < n; i++)
        printf("%s\n", data[record[res[i+1]][1]]);

    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