HEU 5001 Inversion
1
/**************************************
2
Problem: HEU 5001 Inversion
3
Time: 0.0000 s
4
Memory: 240 k
5
Accepted Time: 2009-03-28 12:57:21
6
Tips: 数字排列
7
**************************************/
8
#include <stdio.h>
9
#include <string.h>
10
int 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
/**************************************2
Problem: HEU 5001 Inversion3
Time: 0.0000 s4
Memory: 240 k 5
Accepted Time: 2009-03-28 12:57:216
Tips: 数字排列 7
**************************************/8
#include <stdio.h>9
#include <string.h>10
int 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
else35
{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




浙公网安备 33010602011771号