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 ...
随机推荐
- linux常用命令:cat 命令
cat命令的用途是连接文件或标准输入并打印.这个命令常用来显示文件内容,或者将几个文件连接起来显示,或者从标准输入读取内容并显示,它常与重定向符号配合使用. 1.命令格式: cat [选项] [文件] ...
- C# 调整控件的Z顺序
当窗口或者容器控件中的控件在布局过程中发生重叠的时候,会出现层次性.Z顺序较大的控件会遮挡Z顺序较小的控件,放在顶层的控件会挡住放在底层的控件. 1.编辑一个这样的窗口(使用Label控件) 2.添加 ...
- 实现Winform 跨线程安全访问UI控件
在多线程操作WinForm窗体上的控件时,出现“线程间操作无效:从不是创建控件XXXX的线程访问它”,那是因为默认情况下,在Windows应用程序中,.NET Framework不允许在一个线程中直接 ...
- xml.dom——文档对象模型API
文档对象模型,或者“DOM”,是一个跨语言API的World Wide Web Consortium(W3C)来访问和修改XML文档.DOM的实现提供了一个XML文档树结构,或允许客户机代码从头开始建 ...
- 数据库 SQL 优化大总结之:百万级数据库优化方案
网上关于SQL优化的教程很多,但是比较杂乱.近日有空整理了一下,写出来跟大家分享一下,其中有错误和不足的地方,还请大家纠正补充. 这篇文章我花费了大量的时间查找资料.修改.排版,希望大家阅读之后,感觉 ...
- 计算概论(A)/基础编程练习1(8题)/1:大象喝水
#include<stdio.h> int main() { ; // n < 100 scanf("%d", &n); // 循环遍历判断 再进行平方和 ...
- camera按键采集图像及waitKey的用法(转)
源: camera按键采集图像及waitKey的用法
- python通过sftp远程传输文件
python提供了一个第三方模块paramiko,通过这个模块可以实现两台机器之间的网络连接,sftp是paramiko的一个方法,使用sftp可以在两台机器之间互相传输 拷贝文件.然而paramik ...
- django模板-自定义标签、过滤器
自定义标签或者过滤器的步骤 ①将要创建自定义标签或过滤器的app加入settings文件的installed_apps中 ②在app中创建templatetags目录,类型为包即packages ③在 ...
- P2590 [ZJOI2008]树的统计(树链剖分)
P2590 [ZJOI2008]树的统计 虽然是入门树剖模板 但是我终于1A了(大哭) 懒得写啥了(逃 #include<iostream> #include<cstdio> ...