字符串处理 Codeforces Round #297 (Div. 2) B. Pasha and String
/*
题意:给出m个位置,每次把[p,len-p+1]内的字符子串反转,输出最后的结果
字符串处理:朴素的方法超时,想到结果要么是反转要么没有反转,所以记录
每个转换的次数,把每次要反转的反转就不超时了:)
*/
#include <cstdio>
#include <algorithm>
#include <cstring>
using namespace std; const int MAXN = 2e5 + ;
const int INF = 0x3f3f3f3f;
char s[MAXN];
int to[MAXN]; int main(void) //Codeforces Round #297 (Div. 2) B. Pasha and String
{
int m;
scanf ("%s", s + );
int len = strlen (s + );
scanf ("%d", &m);
while (m--)
{
int p; scanf ("%d", &p);
int q = len - p + ;
to[p]++;
} int sum = ;
for (int i=; i<=len/; ++i)
{
sum += to[i];
if (sum & ) swap (s[i], s[len-i+]);
}
printf ("%s", s + ); return ;
} /*
abcdef
1
2
vwxyz
2
2 2
abcdef
3
1 2 3
*/
字符串处理 Codeforces Round #297 (Div. 2) B. Pasha and String的更多相关文章
- 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 ...
- Codeforces Round #297 (Div. 2)A. Vitaliy and Pie 水题
Codeforces Round #297 (Div. 2)A. Vitaliy and Pie Time Limit: 2 Sec Memory Limit: 256 MBSubmit: xxx ...
- Codeforces Round #297 (Div. 2)E. Anya and Cubes 折半搜索
Codeforces Round #297 (Div. 2)E. Anya and Cubes Time Limit: 2 Sec Memory Limit: 512 MBSubmit: xxx ...
- Codeforces Round #297 (Div. 2)D. Arthur and Walls 暴力搜索
Codeforces Round #297 (Div. 2)D. Arthur and Walls Time Limit: 2 Sec Memory Limit: 512 MBSubmit: xxx ...
- Codeforces Round #297 (Div. 2)C. Ilya and Sticks 贪心
Codeforces Round #297 (Div. 2)C. Ilya and Sticks Time Limit: 2 Sec Memory Limit: 256 MBSubmit: xxx ...
- BFS Codeforces Round #297 (Div. 2) D. Arthur and Walls
题目传送门 /* 题意:问最少替换'*'为'.',使得'.'连通的都是矩形 BFS:搜索想法很奇妙,先把'.'的入队,然后对于每个'.'八个方向寻找 在2*2的方格里,若只有一个是'*',那么它一定要 ...
- 贪心 Codeforces Round #297 (Div. 2) C. Ilya and Sticks
题目传送门 /* 题意:给n个棍子,组成的矩形面积和最大,每根棍子可以-1 贪心:排序后,相邻的进行比较,若可以读入x[p++],然后两两相乘相加就可以了 */ #include <cstdio ...
- 模拟 Codeforces Round #297 (Div. 2) A. Vitaliy and Pie
题目传送门 /* 模拟:这就是一道模拟水题,看到标签是贪心,还以为错了呢 题目倒是很长:) */ #include <cstdio> #include <algorithm> ...
- Codeforces Round #184 (Div. 2) E. Playing with String(博弈)
题目大意 两个人轮流在一个字符串上删掉一个字符,没有字符可删的人输掉游戏 删字符的规则如下: 1. 每次从一个字符串中选取一个字符,它是一个长度至少为 3 的奇回文串的中心 2. 删掉该字符,同时,他 ...
随机推荐
- 获取Wifi密码,不知道是不是真的
package com.example.wifipassword; import java.util.List; import android.app.Activity; import android ...
- MapReduce简述、工作流程及新旧API对照
什么是MapReduce? 你想数出一摞牌中有多少张黑桃.直观方式是一张一张检查而且数出有多少张是黑桃. MapReduce方法则是: 1. 给在座的全部玩家中分配这摞牌. 2. 让每一个玩家数自己手 ...
- 【HDU 5384】Danganronpa(AC自己主动机)
看官方题解貌似就是个自己主动机裸题 比赛的时候用kuangbin的AC自己主动机模板瞎搞的,居然A了,并且跑的还不慢.. 存下模板吧 #include<cstdio> #include&l ...
- VUE 之 路由 VueRouter
1.VueRouter的安装 1.1.https://unpkg.com/vue-router/dist/vue-router.js下载安装. 1.2.<script src="./s ...
- cocos2d-x交叉编译到安卓
ccocos2d-x是一个基于MIT协议的开源框架,用于构建游戏.应用程序和其它图形界面交互应用. 它的最大特点就是跨平台性,支持IOS, Android.Windows, WindowsPhone等 ...
- filename extension
题目描述 Please create a function to extract the filename extension from the given path,return the extra ...
- 获取浏览器屏幕高度(js,jq)
javascript IE中:document.body.clientWidth ==> BODY对象宽度document.body.clientHeight ==> BODY对象高度do ...
- 从零开始徒手撸一个vue的toast弹窗组件
相信普通的vue组件大家都会写,定义 -> 引入 -> 注册 -> 使用,行云流水,一气呵成,但是如果我们今天是要自定义一个弹窗组件呢? 首先,我们来分析一下弹窗组件的特性(需求): ...
- STL Algorithms 之 unique
C++的文档中说,STL中的unique是类似于这样实现的: template <class ForwardIterator> ForwardIterator unique ( Forwa ...
- 推箱子 Sokoban(华中农业比赛)
点这里 打开题目链接 点击打开链接 题目就是我们玩过的推箱子: 一顿暴力广搜:加状态标记.状态压缩需要用到一个类似于康拓的思想来压缩:所以容易TLE,搜索就是用一个int型的数字来表示一个状态, ...