zoukankan      html  css  js  c++  java
  • 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;
    }
  • 相关阅读:
    大型网站架构系列:20本技术书籍推荐
    程序员进阶顺序
    乐观锁与悲观锁——解决并发问题
    Redis的事务功能详解
    驱动开发(8)处理设备I/O控制函数DeviceIoControl
    钱币兑换问题(杭电1284)(母函数)
    jqm文件上传,上传图片,jqm的表单操作,jqm的ajax的使用,jqm文件操作大全,文件操作demo
    问:简述一下内部类的实质是什么?
    Android 删除新版安卓fragment_main.xml
    保温饭盒毕业设计程序
  • 原文地址:https://www.cnblogs.com/111qqz/p/4403449.html
Copyright © 2011-2022 走看看