现在的位置: 首页 > 综合 > 正文

HEU 5001 Inversion

2012年08月11日 ⁄ 综合 ⁄ 共 1305字 ⁄ 字号 评论关闭
 1/**************************************
 2Problem: HEU 5001 Inversion
 3Time: 0.0000 s
 4Memory: 240 k 
 5Accepted Time: 2009-03-28 12:57:21
 6Tips: 数字排列 
 7**************************************/

 8#include <stdio.h>
 9#include <string.h>
10int main()
11{
12    int n;
13    while(1)
14    {
15        scanf("%d",&n);
16        if(n==0)break;
17        char ch[5];
18        int i,j,a[60],b[60];
19        scanf("%s",ch);
20        for(i=0;i<n;i++)scanf("%d",&a[i]);
21        if(ch[0]=='P')
22        {    
23            for(i=0;i<n;i++)
24            {
25                int count=0;
26                for(j=0;;j++)
27                {
28                    if(a[j]>i+1)count++;
29                    else if(a[j]==i+1)break;
30                }

31                b[i]=count;
32            }

33        }

34        else
35        {
36            bool c[60];
37            memset(c,1,sizeof(c));
38            for(i=0;i<n;i++)
39            {
40                j=0;
41                int count=0;
42                while(j!=a[i])
43                {
44                    if(c[count++])j++;
45                }

46                while(!c[count])count++;
47                b[count]=i+1;
48                c[count]=0;
49            }

50        }

51        for(i=0;i<n-1;i++)printf("%d ",b[i]);
52        printf("%d\n",b[i]);
53    }

54    return 0;
55}

56

抱歉!评论已关闭.