zoukankan      html  css  js  c++  java
  • 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 MB
    Submit: xxx  Solved: 2xx

    题目连接

    http://codeforces.com/contest/525/problem/B

    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 ≤ ai; ai ≤ |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
     
    Input
    vwxyz
    2
    2 2
     
    Input
    abcdef
    3
    1 2 3

    Sample Output

    Output
    aedcbf
    Output
    vwxyz
    Output
    fbdcea

    HINT

    题意:

    给你一个字符串,然后给你一个数字i,然后i到s.size()-i直接的位置全部翻转,然后问你m次操作之后,是什么样子

    题解:

    首先,只有翻转奇数次和翻转偶数次两种情况,我们用一个类似前缀和的操作,就可以处理出这个位置究竟翻转了多少次,然后输出就好啦

    ~(≧▽≦)/~啦啦啦,这道题完啦

    代码:

    //qscqesze
    #include <cstdio>
    #include <cmath>
    #include <cstring>
    #include <ctime>
    #include <iostream>
    #include <algorithm>
    #include <set>
    #include <vector>
    #include <sstream>
    #include <queue>
    #include <typeinfo>
    #include <fstream>
    #include <map>
    typedef long long ll;
    using namespace std;
    //freopen("D.in","r",stdin);
    //freopen("D.out","w",stdout);
    #define sspeed ios_base::sync_with_stdio(0);cin.tie(0)
    #define maxn 400010
    #define mod 10007
    #define eps 1e-9
    //const int inf=0x7fffffff;   //无限大
    const int inf=0x3f3f3f3f;
    /*
    
    */
    //**************************************************************************************
    inline ll read()
    {
        int x=0,f=1;char ch=getchar();
        while(ch<'0'||ch>'9'){if(ch=='-')f=-1;ch=getchar();}
        while(ch>='0'&&ch<='9'){x=x*10+ch-'0';ch=getchar();}
        return x*f;
    }
    int flag[maxn];
    int main()
    {
        string s;
        cin>>s;
        int n;
        cin>>n;
        for(int i=0;i<n;i++)
        {
            int x=read();
            flag[x-1]++;
        }
        for(int i=1;i<=s.size()/2;i++)
        {
            flag[i]+=flag[i-1];
        }
        for(int i=0;i<s.size();i++)
        {
            if(i<s.size()/2)
            {
                if(flag[i]%2==0)
                    cout<<s[i];
                else
                    cout<<s[s.size()-i-1];
            }
            else
            {
                if(flag[s.size()-i-1]%2==0)
                    cout<<s[i];
                else
                    cout<<s[s.size()-i-1];
            }
        }
    }
  • 相关阅读:
    基于ASP.NET WEB API实现分布式数据访问中间层(提供对数据库的CRUD)
    C# 实现AOP 的几种常见方式
    SignalR的另类实现技巧
    通过winform+模拟登录实现快速一键登录到人才招聘网站
    Winform应用程序实现通用遮罩层二
    近期开发项目中用到的编码小技巧汇总说明
    详解:基于WEB API实现批量文件由一个服务器同步快速传输到其它多个服务器功能
    关于Quartz.NET作业调度框架的一点小小的封装,实现伪AOP写LOG功能
    trackViewer 氨基酸位点变异位置图谱展示
    python基础-PyYaml操作yaml文件
  • 原文地址:https://www.cnblogs.com/qscqesze/p/4371790.html
Copyright © 2011-2022 走看看