codeforces 525 B. Pasha and String
http://codeforces.com/problemset/problem/525/B
1题意是说一个字符串,进行m次颠倒变换(从a[i]位置到a[l-i+1]位置),问得到的字符串。容易发现,对于越在里边(对称,也就是越靠近中间位置)的字符,调换的次数越多。我们可以把a[i]从小到大排序。然后经过分析发现,把两个相邻的a[i]分为一组,做处理,如果m为奇数,最后还剩下a[m]没有被分组,要单独处理a[m]细节上要注意st数组是从st[0]开始的...好吧的确不方便,适牛也说我了。。数组下标以后还是从0开始吧。。。主要是受高中OI用的pascal的影响。。。那个数组下标随便啊。代码:
2
3
4
5
6 /* ***********************************************
7 Author :111qqz
8 Created Time :2016年02月22日 星期一 23时39分51秒
9 File Name :code/cf/problem/525B.cpp
10 ************************************************ */
11
12 #include <iostream>
13 #include <algorithm>
14 #include <cstring>
15 #include <cmath>
16 #include <cstdio>
17
18 using namespace std;
19
20 int m,k,len;
21 const int N=2E5+7;
22 int a[N];
23 char st[N];
24
25 int main()
26 {
27 cin>>st;
28 scanf("%d",&m);
29 for ( int i = 1 ; i <= m ; i++ )
30 scanf("%d",&a[i]);
31 sort(a+1,a+m+1);
32 k = 1;
33 len = strlen(st);
34 while (k<=m)
35 {
36 for ( int j = a[k] ; j <= a[k+1]-1 ; j++)
37 swap(st[j-1],st[len-j]);
38 k = k + 2;
39 }
40 if ( m %2==1 )
41 for ( int i = a[m]; i <= len/2 ; i++ )
42 swap(st[i-1],st[len-i]);
43 cout<<st<<endl;
44 return 0;
45 }