• hust新人赛模拟20150407 F


    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;
    }
  • 相关阅读:
    .Net开发笔记(二十一) 反射在.net中的应用
    .Net开发笔记(二十)创建一个需要授权的第三方组件
    .Net开发笔记(十九) 创建一个可以可视化设计的对象
    .net开发笔记(十八) winform中的等待框
    .Net开发笔记(十七) 应用程序扩展
    java连接https时禁用证书验证.
    How to disable SSL certificate checking with Spring RestTemplate?(使用resttemplate访问https时禁用证书检查)
    webpack打包调试react并使用babel编译jsx配置方法
    动态改变spring定时任务执行频率
    在java代码中,用xslt处理xml文件
  • 原文地址:https://www.cnblogs.com/111qqz/p/4403449.html
Copyright © 2020-2023  润新知