ARC077C pushpush

~~~题面~~~

题解:

  貌似一般c题都是递推。。。

  观察到最后一个插入的数一定在第一个,倒数第二个插入的数一定在倒数第一个,倒数第三个插入的数一定在第2个,倒数第四个插入的数一定在倒数第2个……

  O(n) 的把数填进数组即可。

  要证明的话想一想构造方式就知道了。

 1     #include<bits/stdc++.h>
 2     using namespace std;
 3     #define R register int
 4     #define AC 201000
 5      
 6     int n, l, r;
 7     int s[AC], ans[AC];
 8      
 9     inline int read()
10     {
11         int x = 0;char c = getchar();
12         while(c > '9' || c < '0') c = getchar();
13         while(c >= '0' && c <= '9') x = x * 10 + c - '0', c = getchar();
14         return x;
15     }
16      
17     void pre()
18     {
19         n = read(), l = 1, r = n;
20         for(R i = 1; i <= n; i ++) s[i] = read();
21     }
22      
23     void work()
24     {
25         int now = 0;
26         for(R i = n; i; i --)
27         {
28             if(!now) ans[l ++] = s[i];
29             else ans[r --] = s[i];
30             now ^= 1;
31         }
32         for(R i = 1; i <= n; i ++) printf("%d ", ans[i]);
33     }
34      
35     int main()
36     {
37         //freopen("in.in", "r", stdin);
38         pre();
39         work();
40         //fclose(stdin);
41         return 0;
42     }
View Code

猜你喜欢

转载自www.cnblogs.com/ww3113306/p/9827727.html
arc