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

暴力一发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. [JS]省市区数据及方法调用

    调用方法: function GetProvinceByid(id) { if (id == null || id == undefined || id == "") return ...

  2. 工具-Quick time播放器

    拍屏的视频.素材视频等,用Quick time观看 1.左下角可切换时间/帧编号,直观看到某pose的帧位置: 2.播放进度条上有卡尺,可选择部分视频,显示-仅播放所选部分,点上显示-循环,可以反复观 ...

  3. redis的持久化 rdb和aof

    1.rdb(Redis DataBase) 当满足条件时,redis单独会fork(创建)一个新的线程,会先将内存中的数据写入到一个临时文件中,待持久化过程都结束了,再用这个临时文件替换上次已经持久化 ...

  4. Web网页数据抓取(C/S)

    通过程序自动的读取其它网站网页显示的信息,类似于爬虫程序.比方说我们有一个系统,要提取BaiDu网站上歌曲搜索排名.分析系统在根据得到的数据进行数据分析.为业务提供参考数据. 为了完成以上的需求,我们 ...

  5. ES 6 : Math对象的扩展

    ES6在Math对象上新增了17个与数学相关的方法.所有这些方法都是静态方法,只能在Math对象上调用. 1.Math.trunc() Math.trunc方法用于去除一个数的小数部分,返回整数部分. ...

  6. 初始化git

    git config --global user.name "Firstname Lastname" git config --global user.email "yo ...

  7. 所需的防伪表单字段“__RequestVerificationToken”不存在

    错误提示为:所需的防伪表单字段"__RequestVerificationToken"不存在. <%:Html.AntiForgeryToken()%> 在mvc4中的 ...

  8. sqlite增删改查

    <?xml version="1.0" encoding="utf-8"?> <RelativeLayout xmlns:android=&q ...

  9. 百度地图api写在html上可以实现,在jsp上会出现Bmap未定义的问题

    在html上引用时用:<script type="text/javascript" src="http://api.map.baidu.com/api?v=2.0& ...

  10. SpringMVC之ModelAndView的简单使用

    可以使用ModelAndView来跳转页面和传值,具体用法如下: 构造方法的参数是要跳转的页面! 通过 ModelAndView 的对象的 AddObject(K,V)方法,可以传入数据! 获得mod ...