FZU - 1989 AntiAC
Problem 1989 AntiACAccept: 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 ...
随机推荐
- Linux初学笔记---关于进程管理等
菜鸟初学: 1. 查看进程用的命令: ps 具体用法 ps -A ro ps -e 显示所有进程 ps -u root 显示root 用户的进程 ps -u root -N 显示非root用户的进程 ...
- Angular factory自定义服务
<!DOCTYPE html><html ng-app="myApp"><head lang="en"> <meta ...
- [转] python 模块学习 hashlib
转自: http://www.cnblogs.com/BeginMan/p/3328172.html 一.hashlib概述 涉及加密服务:14. Cryptographic Services 其中 ...
- Lodop多分出空白页的可能(情况1)
在用Lodop进行打印超文本的时候,本身内容看上去只有一页,却分页分出空白的一页,很有可能有不可见内容的存在,下面是测试的一种情况,如html内部有内容占着空间,却是不可见的,如一些对象,或者如测试内 ...
- nginx-日志统计
#!/bin/bash fd=/tmp/log# pv 点击量echo "###################点击量 --$pv-- #########################&q ...
- poj2115-C Looooops -线性同余方程
线性同余方程的模板题.和青蛙的约会一样. #include <cstdio> #include <cstring> #define LL long long using nam ...
- ubuntu 16.04 samba服务搭建
一:安装 1. sudo apt-get install samba 有询问Yes的地方Yes就行. 无法安装samba 执行 sudo apt-get update 2.等待安装完成,进入配置文件目 ...
- POJ1860(Currency Exchange)
题意: 给出一张各种货币交换的网络,问在网络中交换原有的货币,问货币能否增值? 解析: 判断是否存在正环即可 用spfa 负环和正环的判定方法一样 如果一个点的进队次数超过n次 则存在环 代码如 ...
- bzoj 4552 [Tjoi2016&Heoi2016]排序 (二分答案 线段树)
题目链接:https://www.lydsy.com/JudgeOnline/problem.php?id=4552 题意: 给你一个1-n的全排列,m次操作,操作由两种:1.将[l,r]升序排序,2 ...
- 自学Zabbix8.1 Regular expressions 正则表达式
点击返回:自学Zabbix之路 点击返回:自学Zabbix4.0之路 点击返回:自学zabbix集锦 自学Zabbix8.1 Regular expressions 正则表达式 1. 配置 点击Adm ...