题意:给定一个长度为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. Kinect v2.0 for windows开发环境说明

    官方文档里是这些: Supported Operating Systems and Architectures The following operating systems and architec ...

  2. day14---html基础

    本节内容: 一.HTML 二.CSS 三.JS HTML 1.一套规则,浏览器认识的规则. 2.开发者: 学习Html规则 开发后台程序: - 写Html文件(充当模板的作用) ****** - 数据 ...

  3. Django的virtualenv环境搭建

    安装virtualenv好处多多,可以让当前的项目使用单独的类库,实现系统类库的隔离,所以能够自由地控制当前项目类库的版本,不受系统类库的影响:还有其他N多好处. 下面是安装说明和使用示例: 首先安装 ...

  4. fallacies of distributed computing

    The network is reliable. Latency is zero. Bandwidth is infinite. The network is secure. Topology doe ...

  5. mongoDB研究笔记:分片集群的工作机制

    上面的(http://www.cnblogs.com/guoyuanwei/p/3565088.html)介绍了部署了一个默认的分片集群,对mongoDB的分片集群有了大概的认识,到目前为止我们还没有 ...

  6. Linux 学习笔记(一) 入门

    Shell 显示Shell类型 $ps 切换Shell $[Shell 名称]  ex. $tcsh 快捷键 Ctrl + Z:挂起,可用jobs查看到,fg恢复运行 Ctrl + W:删除单词 Ct ...

  7. Redis 队列操作

    class Program { //版本2:使用Redis的客户端管理器(对象池) public static IRedisClientsManager redisClientManager = ne ...

  8. Jexus针对Asp.net core应用程序的六大不可替代的优势

    1,配置简便:在Jexus上,Asp.net core只是Jexus上的一个"站点",因此,只需在Jexus上配置这个站点就行,无需其它配置: 2,操作统一:Jexus停止这个站点 ...

  9. select * from table 时间长

    优化中发现一个存储过程执行20秒通过profiler 抓取发现时间主要消耗在一个select * from 表,那么问题来了select几万数据竟然花了将近20秒? 问题排查清了程序前端使用了data ...

  10. 设计模式之美:State(状态)

    索引 意图 结构 参与者 适用性 效果 相关模式 实现 实现方式(一):由 ConcreteState 指定它的后继 State. 意图 允许一个对象在其内部状态改变时改变它的行为.对象看起来似乎修改 ...