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 Cloud 路由网关服务端
修改application.properties配置文件:服务端口号.本机名称: 启动注册中心:java -jar uap-register-server-1.0.jar --spring.confi ...
- Jmeter 通过json Extracted 来获取 指定的值的id
在没有 精确或模糊查询的接口时可以使用jmeter 获取指定的值的ID import java.lang.String ; String getTargetName="iphone632g& ...
- linux_目录基本操作
ls命令 ls命令用来显示目标列表,在Linux中是使用率较高的命令.ls命令的输出信息可以进行彩色加亮显示,以分区不同类型的文件. 语法 $ ls [选项] [目录] 选项 说明 -a 显示所有档案 ...
- poj 3352 Road Construction(边双连通分量+缩点)
题目链接:http://poj.org/problem?id=3352 这题和poj 3177 一样,参考http://www.cnblogs.com/frog112111/p/3367039.htm ...
- 如何利用Hadoop存储小文件
**************************************************************************************************** ...
- __new__ __init__区别
1 class A(object): 2 def __init__(self,*args, **kwargs): 3 print "init A" 4 def __new__(cl ...
- delphi property read writer 如何使用
type TMyClass = class(TObject) private FMyName: string; FMyAge: Integer; procedure SetAge(age: Integ ...
- BZOJ1042 HAOI2008硬币购物(任意模数NTT+多项式求逆+生成函数/容斥原理+动态规划)
第一眼生成函数.四个等比数列形式的多项式相乘,可以化成四个分式.其中分母部分是固定的,可以多项式求逆预处理出来.而分子部分由于项数很少,询问时2^4算一下贡献就好了.这个思路比较直观.只是常数巨大,以 ...
- Codeforces Round #410 (Div. 2) B
B. Mike and strings time limit per test 2 seconds memory limit per test 256 megabytes input standard ...
- MT【40】一道联赛二试题
让我通过这道题来演示如何利用切比雪夫多项式的内功心法: 评:如此大道至简,当年为之叫绝的精彩的做法