FZU - 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
Output
Sample Input
Sample Output
#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的更多相关文章
- FZU1989 AntiAC —— 字符串
题目链接:https://vjudge.net/problem/FZU-1989 Problem 1989 AntiAC Accept: 79 Submit: 399Time Limit: 4 ...
- FZU 2137 奇异字符串 后缀树组+RMQ
题目连接:http://acm.fzu.edu.cn/problem.php?pid=2137 题解: 枚举x位置,向左右延伸计算答案 如何计算答案:对字符串建立SA,那么对于想双延伸的长度L,假如有 ...
- FZU 1914 单调队列
题目链接:http://acm.fzu.edu.cn/problem.php?pid=1914 题意: 给出一个数列,如果它的前i(1<=i<=n)项和都是正的,那么这个数列是正的,问这个 ...
- ACM: FZU 2105 Digits Count - 位运算的线段树【黑科技福利】
FZU 2105 Digits Count Time Limit:10000MS Memory Limit:262144KB 64bit IO Format:%I64d & ...
- FZU 2112 并查集、欧拉通路
原题:http://acm.fzu.edu.cn/problem.php?pid=2112 首先是,票上没有提到的点是不需要去的. 然后我们先考虑这个图有几个连通分量,我们可以用一个并查集来维护,假设 ...
- ACM: FZU 2107 Hua Rong Dao - DFS - 暴力
FZU 2107 Hua Rong Dao Time Limit:1000MS Memory Limit:32768KB 64bit IO Format:%I64d & %I6 ...
- ACM: FZU 2112 Tickets - 欧拉回路 - 并查集
FZU 2112 Tickets Time Limit:3000MS Memory Limit:32768KB 64bit IO Format:%I64d & %I64u P ...
- ACM: FZU 2102 Solve equation - 手速题
FZU 2102 Solve equation Time Limit:1000MS Memory Limit:32768KB 64bit IO Format:%I64d & ...
- ACM: FZU 2110 Star - 数学几何 - 水题
FZU 2110 Star Time Limit:1000MS Memory Limit:32768KB 64bit IO Format:%I64d & %I64u Pr ...
随机推荐
- Spring及Spring Boot 国内快速开发框架
http://www.javacoder.top/home.jsp# http://springboot.fun/ 一个常用的支付子项目 https://gitee.com/52itstyle/spr ...
- 批处理-For详解
大纲 一 前言 二 for语句的基本用法 三 for /f (delims.tokens.skip.eol.userbackq.变量延迟) 四 for /r (递归遍历) 五 for /d (遍历目录 ...
- [转帖]linux 内存管理——内核的shmall 和shmmax 参数
(转)linux 内存管理——内核的shmall 和shmmax 参数 内核的 shmall 和 shmmax 参数 SHMMAX= 配置了最大的内存segment的大小 ------>这个 ...
- intval()和int()
int intval ( mixed $var [, int $base ] ) 通过使用特定的进制转换(默认是十进制),参数base表示进制,只有当var是字符串时,base才会有意义,表示按 ...
- ionic2/3注册安卓返回
如果使用了 this.app.getRootNav().push()以及this.navCtrl.push(); 则在注册安卓返回键的时候 registerBackButtonAction() ...
- iptables防火墙配置
iptables防火墙配置 一.防火墙简介 1.功能: 1)通过源端口,源IP地址,源MAC地址,包中特定标记和目标端口,IP,MAC来确定数据包是否可以通过防火墙 2)分割内网和外网[附带的路由器的 ...
- js邏輯
js的邏輯對象可以用於將非邏輯對象轉換為邏輯 var a=new Boolean(); a為false的幾種情況,0,-0,null,false,“”,undefined,NAN
- jsp servlet 的 请求转发和重定向
以前对于servlet和servlet/jsp之间的跳转路径问题感到很迷惑,今天亲自动手实验了一把,总结如下: servlet已经是项目根路径下面的资源了,所以servlet跳转的时候,在跳转路径上面 ...
- BZOJ1030[JSOI2007]文本生成器——AC自动机+DP
题目描述 JSOI交给队员ZYX一个任务,编制一个称之为“文本生成器”的电脑软件:该软件的使用者是一些低幼人群,他们现在使用的是GW文本生成器v6版.该软件可以随机生成一些文章―――总是生成一篇长度固 ...
- shell(2)-&& 与 || 逻辑或与非
test 命令测试 -常见的测试类型–测试文件状态–字符串比较–整数值比较–逻辑测试&& 如果是“前面”(真),则“后面”[ -f /var/run/dhcpd.pid ] & ...