zoukankan      html  css  js  c++  java
  • FZU

       Problem 1989 AntiAC

    Accept: 93    Submit: 444
    Time Limit: 4000 mSec    Memory Limit : 32768 KB

     Problem Description

    Usually, in programming contests all you wait is “AC” (abbreviation of AekdyCoin).We find that boring.

    In this task we do the opposite. We will give you a string consists of only uppercase letters. You should remove some letters so that there is no “AC” in the result string. Return the result string with the longest length. If there is more than one string with the longest length, return lexicographically smallest one.

     Input

    In the first line there is an integer T, indicates the number of test cases. (T <= 100).In each case, there contains one string. The length of string is no longer than 10000.

     Output

    For each case, output “Case idx: “ first where idx is the index of the test case start from 1, then output the result string.

     Sample Input

    3
    A
    ACA
    ACBWCA

     Sample Output

    Case 1: A
    Case 2: AA
    Case 3: ABWCA
     
    分析 
      贪心。把连续的AC块拿出来处理,处理结果必然是多个C+多个A,这样我们需要分别计算A和C的数量(AAACCAAC看作ACAC,记录数量),从而拼接出最长的CA段
     
    #include<iostream>
    #include<cstdio>
    #include<cmath>
    #include<cstdlib>
    #include<algorithm>
    #include<cstring>
    #include <queue>
    using namespace std;
    typedef long long LL;
    const int maxn = 1e4+5;
    const int mod = 772002+233;
    typedef pair<int,int> pii;
    #define X first
    #define Y second
    #define pb push_back
    #define mp make_pair
    #define ms(a,b) memset(a,b,sizeof(a))
    char s[maxn],ans[maxn];
    int sum[maxn],a[maxn],c[maxn];
    int main(){
        int t;
        scanf("%d",&t);
        int cas=1;
        while(t--){
    
            scanf("%s",s);
            int tot=0,numA,numC;
            int len = strlen(s);
            for(int i=0;i<len;i++){
                if(s[i]!='A'){
                    ans[tot++]=s[i];
                    continue;
                }
                int cnt=0;
    
                while(s[i]=='A'){ //处理压缩ACAC段
                    numA=0,numC=0;
                    while(s[i]=='A') numA++,i++;
                    while(s[i]=='C') numC++,i++;
                    sum[++cnt]=numA; //odd
                    sum[++cnt]=numC; //even
                }
                c[0]=0;
                for(int j=2;j<=cnt;j+=2){
                    c[j]=c[j-2]+sum[j];
                }
                a[cnt+1]=0;
                for(int j=cnt-1;j>=1;j-=2){
                    a[j]=a[j+2]+sum[j];
                }
                int tlen=0,clen=0,alen=0;
                for(int j=0;j<=cnt;j+=2){
                    if(c[j]+a[j+1]>tlen){
                        tlen = c[j]+a[j+1];
                        clen = c[j];
                        alen = a[j+1];
                    }
                }
                for(int j=0;j<clen;j++){
                    ans[tot++]='C';
                }
                for(int j=0;j<alen;j++){
                    ans[tot++]='A';
                }
                ans[tot++]=s[i];
            }
            ans[tot]=0;
            printf("Case %d: ",cas++);
            puts(ans);
        }
        return 0;
    }
  • 相关阅读:
    Ellipse4SL 的安装包和环境配置要求
    什么是SOHO人
    D2上的Silverlight
    银光团队项目正式启动,欢迎您的参与!
    Silverlight开发团队招募SOHO团员若干
    SOHO新的生活方式
    [银客北京开发团队]承接各种Silverlight和WPF外包项目和合作项目
    微软Silverlight 3.0 概观
    grers
    翻译电文
  • 原文地址:https://www.cnblogs.com/fht-litost/p/8538466.html
Copyright © 2011-2022 走看看