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 ...
随机推荐
- JavaScript两数相加(踩坑)记录
Adding two numbers concatenates them instead of calculating the sum JavaScript里两个变量 var a = 2: var b ...
- Docker安装指定版本
今天新增一个Docker服务器,Docker安装顺利,启动hello-world测试的时候却出现了问题: $ docker run hello-worldUnable to find image 'h ...
- centos7安装浏览器
firefox(火狐) sudo yum install firefox chrome(谷歌) 添加源:sudo wget http://repo.fdzh.org/chrome/google-chr ...
- the project already contains a form or module named pcm001怎麼解決
the project already contains a form or module named pcm001怎麼解決 菜单Project -> Remove from project.. ...
- javascript 中的后退和前进到上下一页
jsp页面中要返回到上一页可以使用的方法有: 一不刷新: window.history.back(); //返回上一页,这里是利用的浏览器的缓存,返回后数据不会刷新;下一页就用:window.his ...
- Python的数据类型和运算
一.Python数据类型 变量所指向的值是有自己独特的数据类型的,这些数据类型可能代表不同的数据,在Python中,主要有以下几种数据类型: 整形(int) 在计算机中,整数的位数其实是有范围的,并没 ...
- BZOJ3420[POI2013]Triumphal arch&BZOJ5174[Jsoi2013]哈利波特与死亡圣器——树形DP+二分答案
题目大意: 给一颗树,1号节点已经被染黑,其余是白的,两个人轮流操作,一开始B在1号节点,A选择k个点染黑,然后B走一步,如果B能走到A没染的节点则B胜,否则当A染完全部的点时,A胜.求能让A获胜的最 ...
- Luogu4512 【模板】多项式除法(多项式求逆+NTT)
http://blog.miskcoo.com/2015/05/polynomial-division 好神啊! 通过翻转多项式消除余数的影响,主要原理是商只与次数不小于m的项有关. #include ...
- python的多线程到底有没有用?
在群里经常听到这样的争执,有人是虚心请教问题,有人就大放厥词因为这个说python辣鸡.而争论的核心无非就是,python的多线程在同一时刻只会有一条线程跑在CPU里面,其他线程都在睡觉.这是真的吗? ...
- BZOJ2150 部落战争 【带上下界最小流】
题目链接 BZOJ2150 题解 复习: 带上下界网络流两种写法: 不建\(T->S\)的\(INF\)的边,即不考虑源汇点,先求出此时超级源汇的最大流,即无源汇下最大的自我调整,再加入该边,求 ...