码迷,mamicode.com
首页 > 其他好文 > 详细

hust新人赛模拟20150407 F

时间:2015-04-08 21:10:41      阅读:146      评论:0      收藏:0      [点我收藏+]

标签:

F - F
Time Limit:2000MS     Memory Limit:262144KB     64bit IO Format:%I64d & %I64u
Submit Status

Description

Pasha got a very beautiful string s for his birthday, the string consists of lowercase Latin letters. The letters in the string are numbered from 1 to |s| from left to right, where |s| is the length of the given string.

Pasha didn‘t like his present very much so he decided to change it. After his birthday Pasha spent m days performing the following transformations on his string — each day he chose integer ai and reversed a piece of string (a segment) from position ai to position|s| - ai + 1. It is guaranteed that ai ≤ |s|.

You face the following task: determine what Pasha‘s string will look like after m days.

Input

The first line of the input contains Pasha‘s string s of length from 2 to 2·105 characters, consisting of lowercase Latin letters.

The second line contains a single integer m (1 ≤ m ≤ 105) —  the number of days when Pasha changed his string.

The third line contains m space-separated elements ai (1 ≤ aiai ≤ |s|) — the position from which Pasha started transforming the string on the i-th day.

Output

In the first line of the output print what Pasha‘s string s will look like after m days.

Sample Input

Input
abcdef
1
2
Output
aedcbf
Input
vwxyz
2
2 2
Output
vwxyz
Input
abcdef
3
1 2 3
Output
fbdcea

题意是说一个字符串,进行m次颠倒变换(从a[i]位置到a[l-i+1]位置),问得到的字符串。
容易发现,对于越在里边(对称,也就是越靠近中间位置)的字符,调换的次数越多。
我们可以把a[i]从小到大排序。
然后经过分析发现,把两个相邻的a[i]分为一组,做处理,如果m为奇数,最后还剩下a[m]没有被分组,要单独处理a[m]
细节上要注意st数组是从st[0]开始的...好吧的确不方便,适牛也说我了。。数组下标以后还是从0开始吧。。。主要是受高中OI用的pascal的影响。。。那个数组下标随便啊。

代码:
#include <iostream>
#include <algorithm>
#include <cstring>
#include <cmath>
#include <cstdio>

using namespace std;

int m,k,len;
const int N=2E5+7;
int a[N];
char st[N];

int main()
{
    cin>>st;
    scanf("%d",&m);
    for ( int i = 1 ; i <= m ; i++ )
        scanf("%d",&a[i]);
    sort(a+1,a+m+1);
    k = 1;
    len = strlen(st);
    while (k<=m)
    {
        for ( int j = a[k] ; j <= a[k+1]-1 ; j++)
            swap(st[j-1],st[len-j]);
        k = k + 2;
    }
    if ( m %2==1 )
        for ( int i = a[m]; i <= len/2 ; i++ )
            swap(st[i-1],st[len-i]);
    cout<<st<<endl;
    return 0;
}

 

hust新人赛模拟20150407 F

标签:

原文地址:http://www.cnblogs.com/111qqz/p/4403449.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!