-
Notifications
You must be signed in to change notification settings - Fork 19
/
Copy path1988.cpp
72 lines (67 loc) · 1.29 KB
/
1988.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
#include<bits/stdc++.h>
using namespace std;
int n, a[35] ;
int ans[110];
int num;
int find(int x)
{
for (int i = 1 ; i <= n ; i++)
if (abs(a[i]) == x) return i ;
return 0 ;
}
void change(int pos)
{
for(int i = 1, j = pos ; i < j ; i++, j--)
{
swap(a[i],a[j]);
}
for(int i = 1 ; i <= pos ; i++) a[i] = -a[i] ;
}
void solve()
{
int pos ;
num = 0 ;
for (int i = n ; i >= 1 ; i--)
{
if (a[i] == i) continue ;
pos = find(i) ;
if (pos != 1)
{
change(pos);
ans[num++] = pos;
}
if (a[1] > 0)
{
ans[num++] = 1;
a[1] = -a[1];
}
if (i != 1)
{
ans[num++] = i;
change(i);
}
else
{
ans[num++] = 1;
a[i] = -a[i];
}
}
}
int main()
{
int t,cas = 1;
scanf ("%d", &t) ;
while (t--)
{
scanf ("%d", &n) ;
for (int i = 1 ; i <= n ; i++)scanf("%d", &a[i]);
solve();
printf ("%d %d", cas++, num) ;
for (int i = 0 ; i < num ; i++)
{
printf (" %d", ans[i]) ;
}
puts ("") ;
}
return 0 ;
}