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

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

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

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

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

O(len/2)……

 #include<stdio.h>
#include<iostream>
#include<algorithm>
#include<math.h>
#include<string.h>
#include<string>
#include<map>
#include<set>
#include<vector>
#include<queue>
#define M(a,b) memset(a,b,sizeof(a))
using namespace std;
typedef long long ll;
char str[];
bool vis[];
int main(){
gets(str);
int len=strlen(str);
int n,a;
scanf("%d",&n);
for(int i=;i<n;i++){
scanf("%d",&a);
vis[a-]=!vis[a-];
}
int now=;
for(int i=;i<len/;i++){
now^=vis[i];
if(now) swap(str[len-i-],str[i]);
}
puts(str);
return ;
}
/* abcdef
1
2 vwxyz
2
2 2 abcdef
3
1 2 3 */

[ An Ac a Day ^_^ ] CodeForces 525B Pasha and String 技巧的更多相关文章

  1. codeforces B. Pasha and String

    Pasha got a very beautiful string s for his birthday, the string consists of lowercase Latin letters ...

  2. codeforces B. Pasha and String(贪心)

    题意:给定一个长度为len的字符序列,然后是n个整数,对于每一个整数ai, 将字符序列区间为[ai,len-ai+1]进行反转.求出经过n次反转之后的序列! /* 思路1:将区间为偶数次的直接去掉!对 ...

  3. Codeforces Round #297 (Div. 2)B. Pasha and String 前缀和

    Codeforces Round #297 (Div. 2)B. Pasha and String Time Limit: 2 Sec  Memory Limit: 256 MBSubmit: xxx ...

  4. Pasha and String(思维,技巧)

    Pasha and String Time Limit:2000MS     Memory Limit:262144KB     64bit IO Format:%I64d & %I64u S ...

  5. B. Pasha and String

    time limit per test 2 seconds memory limit per test 256 megabytes input standard input output standa ...

  6. 字符串处理 Codeforces Round #297 (Div. 2) B. Pasha and String

    题目传送门 /* 题意:给出m个位置,每次把[p,len-p+1]内的字符子串反转,输出最后的结果 字符串处理:朴素的方法超时,想到结果要么是反转要么没有反转,所以记录 每个转换的次数,把每次要反转的 ...

  7. Codeforces 435B. Pasha Maximizes

    简单贪心.... B. Pasha Maximizes time limit per test 1 second memory limit per test 256 megabytes input s ...

  8. Codeforces 595B - Pasha and Phone

    595B - Pasha and Phone 代码: #include<bits/stdc++.h> using namespace std; #define ll long long # ...

  9. Codeforces 595B. Pasha and Phone 容斥

    B. Pasha and Phone time limit per test 1 second memory limit per test 256 megabytes input standard i ...

随机推荐

  1. Linode VPS上架日本东京2号机房,性能速度评测报告(推荐)

    我非常喜欢的海外免备案vps品牌linode日本机房长期缺货,中国用户想买都买不到.不过近日,陆续有国内朋友收到了Linode邀请,Tokyo 2日本东京机房开启内测,很快正式上架销售. 苦等太久的站 ...

  2. SQL总结之导入导出

    (5)还原数据库[倒库] [数据泵模式]先要在D盘创建个目录,如D:/dbback 然后去plsql中创建目录sql命令:create directory dbback as 'D:\dbback'; ...

  3. urllib模块 | Python 2.7.11

    官方文档: https://docs.python.org/2/library/urllib.html 某博客对官方文档较全的翻译: http://h2byte.com/post/tech/relat ...

  4. Scheme入门

    目前选择的是DrRacket作为IDE,可以去网上搜索下载. 打开软件后,输入如下代码进行 helloworld #lang scheme ;The first program (begin (dis ...

  5. UNIX基础--安装应用程序: Packages 和 Ports

    Packages and Ports 概述 FreeBSD 将许多系统工具捆绑作为基本系统的一部分.另外,FreeBSD 提供了两种补充的技术来安装第三方软件:FreeBSD Ports Collec ...

  6. WinForm ListView

    今天,我学习了公共控件中的ListView的内容. 首先,在利用ListView布置界面时,有以下三个方面: 1.视图:            在其右上方小箭头点击将视图改为Details:或者右键属 ...

  7. CSS绑定

    css绑定会对元素的CSS类进行操作.在某些情况下这将非常有用,例如:当数值是负的时将其高亮显示. (注:如果如果不想直接更改CSS类,而是只要改其中一个样式,则需要使用style绑定) 示例:使用静 ...

  8. 精通javasCRIPT-学习笔记 Features,Functions,Object

    关于学习javasCRIPT的书,市面上太多了,有犀牛书,红宝书,但是他们都类似于一本书,包含js的一切,并没有站在一个高度上,看js的本质,我计划看一看jquery作者resig写的<精通ja ...

  9. Little Puzzlers–List All Anagrams in a Word

    The Solution A major hint is in the fact we are given a dictionary.  Because we are given this dicti ...

  10. HDU 5860 Death Sequence(递推)

    HDU 5860 Death Sequence(递推) 题目链接http://acm.split.hdu.edu.cn/showproblem.php?pid=5860 Description You ...