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

 /*
思路1:将区间为偶数次的直接去掉!对剩下的区间进行反转。超时了,智商上的压制...
*/
#include<iostream>
#include<cstdio>
#include<algorithm>
#include<stack>
#include<cstring>
#include<vector>
#define N 100005
using namespace std;
char mp[*N];
int num[N];
int cnt[N*]; void my_swap(int &a, int &b){
a^=b;
b^=a;
a^=b;
} void my_reverse(int x, int y){
for(int i=x, j=y; i<j; ++i, --j){
char tmp = mp[i];
mp[i] = mp[j];
mp[j] = tmp;
}
} int main() {
scanf("%s", mp+);
int m, mm=;
cin>>m;
for(int i=; i<m; ++i){
scanf("%d", &num[i]);
++cnt[num[i]];
} int len = strlen(mp+);
for(int i=; i<=len/; ++i){
if(cnt[num[i]] + cnt[len-num[i]+])%!=){
int x = num[i];
int begin = x, end= len-x+;
if(begin > end) my_swap(begin, end);
my_reverse(begin, end);
}
}
printf("%s\n", mp+);
}
 /*
思路2:仔细分析,每一个反转的区间左右是对称的,如果[ai, len-ai+1]区间进行反转,
那么就有str[ai]与str[len-ai+1]交换,str[ai+1]与str[len-ai]交换.....
也就是ai位置发生交换,那么ai+1,ai+2...len/2也一定发生交换。如果ai位置的交换的次数
为偶数就不用交换,为奇数就进行交换!
*/
#include<iostream>
#include<cstdio>
#include<algorithm>
#include<stack>
#include<cstring>
#include<vector>
#define N 100005
using namespace std;
char mp[*N];
int cnt[N*];//统计每一个位置交换的次数 int main() {
scanf("%s", mp+);
int m, mm=;
scanf("%d", &m) ;
int len = strlen(mp+);
while(m--){
int x;
scanf("%d", &x);
++cnt[x], ++cnt[len-x+];
} for(int i=; i<=len/; ++i)
cnt[i] += cnt[i-];//第i个位置交换,那么第i+1,i+2..len/2个位置也一定发生交换 for(int i=; i<=len/; ++i)
if(cnt[i]%!=)//奇数位置交换
swap(mp[i], mp[len-i+]);
printf("%s\n", mp+);
}

codeforces B. 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. [ An Ac a Day ^_^ ] CodeForces 525B Pasha and String 技巧

    题意就是一次次翻转字符串 然后输出最终的字符串 暴力一发O(n*m)果然超时了 因为每次翻转的的都是a-1到对称位置 所以一个位置翻转两次等于没有操作 所以只需要记录一下len/2的位置前的操作次数 ...

  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. 字符串处理 Codeforces Round #297 (Div. 2) B. Pasha and String

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

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

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

  6. codeforces Gym 100338E Numbers (贪心,实现)

    题目:http://codeforces.com/gym/100338/attachments 贪心,每次枚举10的i次幂,除k后取余数r在用k-r补在10的幂上作为候选答案. #include< ...

  7. B. Pasha and String

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

  8. Codeforces #541 (Div2) - E. String Multiplication(动态规划)

    Problem   Codeforces #541 (Div2) - E. String Multiplication Time Limit: 2000 mSec Problem Descriptio ...

  9. [Codeforces 1214A]Optimal Currency Exchange(贪心)

    [Codeforces 1214A]Optimal Currency Exchange(贪心) 题面 题面较长,略 分析 这个A题稍微有点思维难度,比赛的时候被孙了一下 贪心的思路是,我们换面值越小的 ...

随机推荐

  1. hdu 5106 组合数学+找规律

    http://acm.hdu.edu.cn/showproblem.php?pid=5106 给定n和r,要求算出[0,r)之间所有n-onebit数的和,n-onebit数是所有数位中1的个数. 对 ...

  2. Java中的一个类怎么调用另一个类中的方法

    如果另一个类中的那个方法是私有的话,就不能直接调用到,如果是其他类型的话看情况,如果是静态的(static)话,直接用类名可以调用到,如果是非静态的,就需要利用另一个类的实例(也就是用那个类生成的对象 ...

  3. Apache Shiro (一)

    参考博客: http://jinnianshilongnian.iteye.com/blog/2018398 1.shiro简介 Apache shiro 是一个JAVA框架,可用于身份难和授权.sh ...

  4. 新装ubuntu12.04需要敲的命令集合

    1.sudo cp /etc/apt/sources.list /etc/apt/sources.list.backup sudo gedit /etc/apt/sources.list copy: ...

  5. Boost 安装

    1.下载boost Windows版,如:boost_1_55_0: 2.运行boostrap.bat,会生成bjam.exe: 3.运行bjam.exe(时间会比较长),会生成一个stage目录里面 ...

  6. Online Judge中基本的输入输出

    一.利用c语言处理输入和输出 1.输入: 在C语言中输入中stdin指针表示标准的输入,scanf默认读取的就是stdin指向的输入,在acm中我们可能需要不断的测试,最好将stdin重定向到某一个文 ...

  7. 解剖SQLSERVER 第九篇 OrcaMDF现在能通过系统DMVs显示元数据(译)

    解剖SQLSERVER 第九篇  OrcaMDF现在能通过系统DMVs显示元数据(译) http://improve.dk/orcamdf-now-exposes-metadata-through-s ...

  8. wireshark长时间抓包分多个文件

    前言 说一说这个问题的由来,一般使用wireshark不需要长时间抓包的,但是有时候遇到网络通信中非常棘手的问题,例如一个小时出现一次或者几个小时出现一次问题的情况,这种情况下就必须长时间抓包了.但是 ...

  9. Xamarin.Android之MvvmCross

    欢迎大家加入以下开源社区 Xamarin-Cn:https://github.com/Xamarin-Cn Mvvmcross-Cn:https://github.com/Mvvmcross-Cn  ...

  10. 可在广域网部署运行的QQ高仿版 -- GG叽叽V2.4,增加远程协助、桌面共享功能(源码)

    QQ的远程协助.或者说桌面共享是一个非常实用的功能,所以,2.4版本的GG复制了它,而且,GG增强了桌面共享的功能,它可以允许指定要共享桌面的区域,这样,对方就只能看到指定区域的桌面,这对节省流量会非 ...