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+;
const int mod = +;
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=;
while(t--){ scanf("%s",s);
int tot=,numA,numC;
int len = strlen(s);
for(int i=;i<len;i++){
if(s[i]!='A'){
ans[tot++]=s[i];
continue;
}
int cnt=; while(s[i]=='A'){ //处理压缩ACAC段
numA=,numC=;
while(s[i]=='A') numA++,i++;
while(s[i]=='C') numC++,i++;
sum[++cnt]=numA; //odd
sum[++cnt]=numC; //even
}
c[]=;
for(int j=;j<=cnt;j+=){
c[j]=c[j-]+sum[j];
}
a[cnt+]=;
for(int j=cnt-;j>=;j-=){
a[j]=a[j+]+sum[j];
}
int tlen=,clen=,alen=;
for(int j=;j<=cnt;j+=){
if(c[j]+a[j+]>tlen){
tlen = c[j]+a[j+];
clen = c[j];
alen = a[j+];
}
}
for(int j=;j<clen;j++){
ans[tot++]='C';
}
for(int j=;j<alen;j++){
ans[tot++]='A';
}
ans[tot++]=s[i];
}
ans[tot]=;
printf("Case %d: ",cas++);
puts(ans);
}
return ;
}

FZU - 1989 AntiAC的更多相关文章

  1. FZU1989 AntiAC —— 字符串

    题目链接:https://vjudge.net/problem/FZU-1989  Problem 1989 AntiAC Accept: 79    Submit: 399Time Limit: 4 ...

  2. FZU 2137 奇异字符串 后缀树组+RMQ

    题目连接:http://acm.fzu.edu.cn/problem.php?pid=2137 题解: 枚举x位置,向左右延伸计算答案 如何计算答案:对字符串建立SA,那么对于想双延伸的长度L,假如有 ...

  3. FZU 1914 单调队列

    题目链接:http://acm.fzu.edu.cn/problem.php?pid=1914 题意: 给出一个数列,如果它的前i(1<=i<=n)项和都是正的,那么这个数列是正的,问这个 ...

  4. ACM: FZU 2105 Digits Count - 位运算的线段树【黑科技福利】

     FZU 2105  Digits Count Time Limit:10000MS     Memory Limit:262144KB     64bit IO Format:%I64d & ...

  5. FZU 2112 并查集、欧拉通路

    原题:http://acm.fzu.edu.cn/problem.php?pid=2112 首先是,票上没有提到的点是不需要去的. 然后我们先考虑这个图有几个连通分量,我们可以用一个并查集来维护,假设 ...

  6. ACM: FZU 2107 Hua Rong Dao - DFS - 暴力

    FZU 2107 Hua Rong Dao Time Limit:1000MS     Memory Limit:32768KB     64bit IO Format:%I64d & %I6 ...

  7. ACM: FZU 2112 Tickets - 欧拉回路 - 并查集

     FZU 2112 Tickets Time Limit:3000MS     Memory Limit:32768KB     64bit IO Format:%I64d & %I64u P ...

  8. ACM: FZU 2102 Solve equation - 手速题

     FZU 2102   Solve equation Time Limit:1000MS     Memory Limit:32768KB     64bit IO Format:%I64d & ...

  9. ACM: FZU 2110 Star - 数学几何 - 水题

     FZU 2110  Star Time Limit:1000MS     Memory Limit:32768KB     64bit IO Format:%I64d & %I64u  Pr ...

随机推荐

  1. CentOS 使用SMB服务 让windows能够上传文件

    1. 新增加用户 useradd zhaobsh 2. 使用 pdbedit的方式新增加用户 pdbedit -a -u zhaobsh 3. 修改smb服务 systemctl restart sm ...

  2. 堆排序获取TopN

    package com.zjl.tool.sort; /** * 求前面的最大K个 解决方案:小根堆 (数据量比较大(特别是大到内存不可以容纳)时,偏向于采用堆) * @author 张恩备 * @d ...

  3. 美化centos7

    在美化前,我们先安装一个扩展源.yum install -y epel-release然后安装字体包yum -y install liberation-mono-fonts 安装gnome-menis ...

  4. 暂时刷完leetcode的一点小体会

    两年前,在实习生笔试的时候,笔试百度,对试卷上很多问题感到不知所云,毫无悬念的挂了 读研两年,今年代笔百度,发现算法题都见过,或者有思路,但一时之间居然都想不到很好的解法,而且很少手写思路,手写代码, ...

  5. python之多线程举例

    # 多线程举例 from threading import Thread from threading import current_thread class messager(Thread): de ...

  6. CSS兼容性详解

    前面的话 对于前端工程师来说,不想面对又不得不面对的一个问题就是兼容性.在几年之前,处理兼容性,一般地就是处理IE低版本浏览器的兼容性.而近几年,随着移动端的发展,工程师也需要注意手机兼容性了.本文将 ...

  7. Minimum Cost POJ - 2516 (模板题 spfa最小费用最大流)

    题意: 人回家,一步一块钱,有x个人,y个房子,求能回家的最大人数且使之费用最小 解析: 就是....套模板,,,, 建图(⊙﹏⊙)...要仔细观察呐 对于人拆不拆都可以  都能过,,,,这里贴上拆开 ...

  8. day31 configparser 配置文件模块

    #__author__: Administrator #__date__: 2018/8/8 # configparse 生成配置文件,配置文会以件.ini结尾 # 对于格式有要求 # 创建配置文档 ...

  9. MT【6】等比数列和的极限

    评:利用等比数列求和公式给出所求数列,再利用反证法证明唯一性.这种反证方法印象中本科高等代数里讲初等对称多项式时出现过.

  10. THUWC2018酱油记

    Day 0 今年的THUWC在我们学校,听说有pretest,感觉有不好的预感.... Day 1 早上7:00在校门口集合,车7:30以后才到,感觉就像在围观 期末考试.来到雅礼洋湖,在这里看到了初 ...