HDU 5583 Kingdom of Black and White(暴力)
http://acm.hdu.edu.cn/showproblem.php?pid=5583
题意:
给出一个01串,现在对这串进行分组,连续相同的就分为一组,如果该组内有x个数,那么就对答案贡献x*x,现在最多可以修改原串中的一个字符,问答案最大可以为多少。
思路:
暴力求解。
一开始只需要预处理分块,计算出每一分块的个数,然后暴力处理一下即可,需要注意分块数为1的情况,此时左右两边都要合并起来。
#include<iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>
using namespace std; const int maxn = 1e5+;
typedef long long ll; char s[maxn];
ll a[maxn];
int top; int main()
{
//freopen("in.txt","r",stdin);
int T;
int kase = ;
scanf("%d",&T);
while(T--)
{
memset(a,,sizeof(a));
scanf("%s",s);
int len = strlen(s);
ll cnt = ;
top = ;
ll tmp = ;
for(int i=;i<len;i++)
{
if(i== || s[i]==s[i-]) cnt++;
else
{
a[++top]=cnt;
tmp+=cnt*cnt;
cnt = ;
}
if(i==len-)
{
a[++top]=cnt;
tmp+=cnt*cnt;
}
}
ll ans = ;
for(int i=;i<=top;i++)
{
ll tt = tmp;
if(i!=)
{
tt=tt-a[i]*a[i]-a[i-]*a[i-];
if(a[i]==)
{
tt-=a[i+]*a[i+];
tt+=(a[i-]+a[i]+a[i+])*(a[i-]+a[i]+a[i+]);
}
else
{
tt+=(a[i-]+)*(a[i-]+)+(a[i]-)*(a[i]-);
}
ans=max(ans,tt);
}
tt = tmp;
if(i!=top)
{
tt=tt-a[i]*a[i]-a[i+]*a[i+];
if(a[i]==)
{
tt-=a[i-]*a[i-];
tt+=(a[i-]+a[i]+a[i+])*(a[i-]+a[i]+a[i+]);
}
else
{
tt+=(a[i]-)*(a[i]-)+(a[i+]+)*(a[i+]+);
}
ans=max(ans,tt);
}
}
if(top==) ans=a[]*a[];
printf("Case #%d: ",++kase);
cout<<ans<<endl;
}
return ;
}
HDU 5583 Kingdom of Black and White(暴力)的更多相关文章
- HDU 5583 Kingdom of Black and White 水题
Kingdom of Black and White Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://acm.hdu.edu.cn/showpr ...
- hdu 5583 Kingdom of Black and White(模拟,技巧)
Problem Description In the Kingdom of Black and White (KBW), there are two kinds of frogs: black fro ...
- hdu 5583 Kingdom of Black and White
Kingdom of Black and White Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/65536 K (Ja ...
- [HDOJ5583]Kingdom of Black and White(暴力)
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=5583 一个01串,求修改一个位置,使得所有数均为0或1的子串长度的平方和最大.先分块,然后统计好原来的 ...
- hdu-5583 Kingdom of Black and White(数学,贪心,暴力)
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=5583 Kingdom of Black and White Time Limit: 2000/1000 ...
- hdu 4948 Kingdom(推论)
hdu 4948 Kingdom(推论) 传送门 题意: 题目问从一个城市u到一个新的城市v的必要条件是存在 以下两种路径之一 u --> v u --> w -->v 询问任意一种 ...
- HDU5583 Kingdom of Black and White
Kingdom of Black and White Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/65536 K (Ja ...
- hdu 4740 The Donkey of Gui Zhou(暴力搜索)
题目地址:http://acm.hdu.edu.cn/showproblem.php?pid=4740 [题意]: 森林里有一只驴和一只老虎,驴和老虎互相从来都没有见过,各自自己走过的地方不能走第二次 ...
- HDU 5943 Kingdom of Obsession 【二分图匹配 匈牙利算法】 (2016年中国大学生程序设计竞赛(杭州))
Kingdom of Obsession Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Oth ...
随机推荐
- loadRunner手动关联, web_reg_save_param_regexp()函数正则匹配字符,赋值给变量
loadRunner写脚本实现登录机票网站,手动关联,获取页面源码中特定字符 手动关联,就是通过函数获取某个步骤生成的字符,赋值给一个变量,这个变量可以作为接下来某个步骤的输入, 以便这个脚本能够在存 ...
- 世界最顶级邮件服务器组合Linux + PMTA + OEMPRO,PowerMTA 安装
世界最顶级邮件服务器组合Linux + PMTA + OEMPRO PowerMTA 安装 PMTA + OEMPRO 这个是发送的组合 PMTA提供的SMTP,OEMPRO是订阅管理以及邮件的过滤 ...
- Censor SCU - 4438
frog is now a editor to censor so-called sensitive words (敏感词). She has a long text (p). Her job is ...
- use right spindle drive
Hardware software interface: HallSupplyLeft: E_BSW_DO_SUP_HCOM_A Left Hall Sensor: E_BSW_DI_HALL_A_1 ...
- P1382 楼房
P1382 楼房 每个矩形拆成2个坐标按$x$轴排序,蓝后$multiset$维护最高值. #include<iostream> #include<cstring> #incl ...
- jQuery操作下拉框的text值和val值
jQuery操作下拉框的text值和val值 1,JS源码 <select name="select1" id="select1" style=" ...
- 05: greenlet:轻量级的并发编程
网络编程其他篇 1.1 greenlet简介 1.greenlet原理 & 使用 1. greenle间切换 1)一个 “greenlet” 是一个很小的独立微线程,可以把它想像成一个堆栈帧, ...
- 20165310 NstSec2019 Week3 Exp1 逆向与Bof基础
20165310 NstSec2019 Week3 Exp1 逆向与Bof基础 一.实验内容 实验目标 本次实践的对象是一个名为pwn1的linux可执行文件. 该程序正常执行流程是:main调用fo ...
- CocoaPods出错
1 Error: pod search Masonry /usr/local/lib/ruby/gems/2.3.0/gems/cocoapods-1.4.0.beta.2/lib/cocoapods ...
- 使用JBarcode生成一维码
需要的jar包,只有jbarcode.jar 链接: https://pan.baidu.com/s/1o9oDPB8 密码: x367 public class Main { //设置条形码高度 p ...