[ An Ac a Day ^_^ ] CodeForces 525B Pasha and String 技巧
题意就是一次次翻转字符串 然后输出最终的字符串
暴力一发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 技巧的更多相关文章
- codeforces B. Pasha and String
Pasha got a very beautiful string s for his birthday, the string consists of lowercase Latin letters ...
- codeforces B. Pasha and String(贪心)
题意:给定一个长度为len的字符序列,然后是n个整数,对于每一个整数ai, 将字符序列区间为[ai,len-ai+1]进行反转.求出经过n次反转之后的序列! /* 思路1:将区间为偶数次的直接去掉!对 ...
- 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 ...
- Pasha and String(思维,技巧)
Pasha and String Time Limit:2000MS Memory Limit:262144KB 64bit IO Format:%I64d & %I64u S ...
- B. Pasha and String
time limit per test 2 seconds memory limit per test 256 megabytes input standard input output standa ...
- 字符串处理 Codeforces Round #297 (Div. 2) B. Pasha and String
题目传送门 /* 题意:给出m个位置,每次把[p,len-p+1]内的字符子串反转,输出最后的结果 字符串处理:朴素的方法超时,想到结果要么是反转要么没有反转,所以记录 每个转换的次数,把每次要反转的 ...
- Codeforces 435B. Pasha Maximizes
简单贪心.... B. Pasha Maximizes time limit per test 1 second memory limit per test 256 megabytes input s ...
- Codeforces 595B - Pasha and Phone
595B - Pasha and Phone 代码: #include<bits/stdc++.h> using namespace std; #define ll long long # ...
- Codeforces 595B. Pasha and Phone 容斥
B. Pasha and Phone time limit per test 1 second memory limit per test 256 megabytes input standard i ...
随机推荐
- 引用Excel.dll 时找不到类型怎么办
将引用(Microsoft.Office.Interop.Excel)的属性"嵌入互操作类型"由True修改为False即可
- 关于Objective-C Associated Objects
一.相关函数 与Associated Objects相关的函数有三个 1 void objc_setAssociatedObject(id object, const void *key, id va ...
- ECStore图片存储采用阿里云OSS(图片存储)服务
主要功能:ECStore图片存储采用阿里云OSS(图片存储)服务 适用版本:ECStore 授权方式:授权域名使用,付费插件 联系方式: QQ 275553385 mail: jimingson ...
- iOS 调用私有函数安装app 卸载 app
1.环境 1.OS X EI Caption 10.11.1 & Xcode 7 2.Xcode安装Command Line Tools 3.iPhone 安装AppSync 2.Mobile ...
- ap143 led修改
以前的硬件版本只使用了一个eth口,新的板子增加了一个eth口,并且增加了响应的通信时使用的灯. led修改涉及到一下的内容: (1)led 对应的gpio口(这个需要根据原理图来定义) 需要修改的源 ...
- 通过反射获取所有的Action 一般用于权限管理
public IList<ActionPermission> GetAllActionByAssembly() { var result = new List<ActionPermi ...
- Dev的GridControl控件选择框的使用
先介绍环境:VS2010,dev11.2 想要达到的效果:,当单击某一行时前面的选择框选中. 在网上找了不少,但是感觉跟我想的做法很不一样(有很多都是再另外添加一个什么CheckBox,这个我在Dev ...
- CentOS6.5 安装mysql5.6.30
1.下载解压由于系统会自带mysql5.1版本的数据库,需要卸载.[root@localhost src]# yum remove -y mysql-libs[root@localhost src]# ...
- H5获取的经纬度,该怎么在百度地图中查看?
之前理所当然的的到百度的坐标拾取系统, 输入H5获取的经纬度坐标,然后查询,然后发现老是有误差,而且误差都是一样的规律:偏实际位置西南方约1000~1500米左右. 以为是H5获取经纬度必然会产生这么 ...
- Android编程获取手机的IMEI
手机在生产时,每部手机均有一个唯一的标识(ID),国际上采用国际移动设备身份码(IMEI, International Mobile Equipment Identity).IMEI是由15位数字组成 ...