[ An Ac a Day ^_^ ] CodeForces 525B Pasha and String 技巧

题意就是一次次翻转字符串 然后输出最终的字符串

暴力一发O(n*m)果然超时了

因为每次翻转的的都是a-1到对称位置

所以一个位置翻转两次等于没有操作

所以只需要记录一下len/2的位置前的操作次数

O(len/2)……

 1 #include<stdio.h>
 2 #include<iostream>
 3 #include<algorithm>
 4 #include<math.h>
 5 #include<string.h>
 6 #include<string>
 7 #include<map>
 8 #include<set>
 9 #include<vector>
10 #include<queue>
11 #define M(a,b) memset(a,b,sizeof(a))
12 using namespace std;
13 typedef long long ll;
14 char str[200005];
15 bool vis[200005];
16 int main(){
17     gets(str);
18     int len=strlen(str);
19     int n,a;
20     scanf("%d",&n);
21     for(int i=0;i<n;i++){
22         scanf("%d",&a);
23         vis[a-1]=!vis[a-1];
24     }
25     int now=0;
26     for(int i=0;i<len/2;i++){
27         now^=vis[i];
28         if(now) swap(str[len-i-1],str[i]);
29     }
30     puts(str);
31     return 0;
32 }
33 /*
34 
35 abcdef
36 1
37 2
38 
39 vwxyz
40 2
41 2 2
42 
43 abcdef
44 3
45 1 2 3
46 
47 */
原文地址:https://www.cnblogs.com/general10/p/5782209.html