[HDOJ5583]Kingdom of Black and White(暴力)
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=5583
一个01串,求修改一个位置,使得所有数均为0或1的子串长度的平方和最大。先分块,然后统计好原来的结果,每次更新块,更新最大值。
#include <algorithm>
#include <iostream>
#include <iomanip>
#include <cstring>
#include <climits>
#include <complex>
#include <fstream>
#include <cassert>
#include <cstdio>
#include <bitset>
#include <vector>
#include <deque>
#include <queue>
#include <stack>
#include <ctime>
#include <set>
#include <map>
#include <cmath> using namespace std; typedef long long ll;
const int maxn = ;
int n;
char s[maxn];
ll grid[maxn]; int main() {
// freopen("in", "r", stdin);
int T;
scanf("%d", &T);
for(int _ = ; _ <= T; _++) {
scanf("%s", s);
memset(grid, , sizeof(grid));
ll cur = , ans = ;
n = ; grid[n] = ;
for(int i = ; s[i]; i++) s[i] == s[i-] ? grid[n]++ : grid[++n] = ;
for(int i = ; i <= n; i++) cur += grid[i] * grid[i];
if(n == ) ans = grid[] * grid[];
else {
for(int i = ; i <= n; i++) {
if(grid[i] == ) ans = max(cur+*(grid[i-]*grid[i+]+grid[i-]+grid[i+]), ans);
else {
if(grid[i-] >= grid[i])
ans = max(cur+*(grid[i-]-grid[i]+), ans);
else
ans = max(cur+*(grid[i]-grid[i-]+), ans);
}
}
}
printf("Case #%d: %I64d\n", _, ans);
}
return ;
}
[HDOJ5583]Kingdom of Black and White(暴力)的更多相关文章
- 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 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 ...
- 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 5583 Kingdom of Black and White(暴力)
http://acm.hdu.edu.cn/showproblem.php?pid=5583 题意: 给出一个01串,现在对这串进行分组,连续相同的就分为一组,如果该组内有x个数,那么就对答案贡献x* ...
- HDU-5583-Kingdom of Black and White(2015ACM/ICPC亚洲区上海站-重现赛)
Kingdom of Black and White ...
- 2015ACM/ICPC亚洲区上海站
5573 Binary Tree(构造) 题意:给你一个二叉树,根节点为1,子节点为父节点的2倍和2倍+1,从根节点开始依次向下走k层,问如何走使得将路径上的数进行加减最终结果得到n. 联想到二进制. ...
- 「WC2018」即时战略
「WC2018」即时战略 考虑对于一条链:直接随便找点,然后不断问即可. 对于一个二叉树,树高logn,直接随便找点,然后不断问即可. 正解: 先随便找到一个点,问出到1的路径 然后找别的点,考虑问出 ...
随机推荐
- yebis error ---depth of field
前几天在墙外无法登陆cnblogs...导致很多blogs就没写了 有几篇比较值得记下来的,但是我已经不记得了,应该和sao有关scalable ambient obscurance 我似乎回忆起一点 ...
- python实现web分页日志查看
当我们维护一个网站时,无论前台还是后台,经常会出现各种个样的问题.有时候问题很难直观的发现,这个时候只能查看各种日志来跟踪问题.但是查看日志有各种个样的问题.首先,要用各种工具登陆到服务器,这个有时候 ...
- CSS预处理器实践之Sass、Less大比拼[转]
什么是CSS预处理器? CSS可以让你做很多事情,但它毕竟是给浏览器认的东西,对开发者来说,Css缺乏很多特性,例如变量.常量以及一些编程语法,代码难易组织和维护.这时Css预处理器就应运而生了.Cs ...
- css 内联元素inline 行框全解
首先看一篇文章: CSS框模型:一切皆为框 — 从行框说起 一 行框 看图说话 上图代表了框模型中的行框.line-height 属性设置行间的距离(行高).该属性会影响行框的布局.在应用到一个块级元 ...
- C# 对委托的BeginInvoke,EndInvoke 及Control 的BeginInvoke,EndInvoke 的理解
using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; usin ...
- 解决Myeclipse 编辑jsp页面卡
解决Myeclipse 编辑jsp页面卡 编辑一个jsp页面时,如果每输入一下,CPU都100%一下,和大家分项一下. 问题: 当你编辑一个jsp页面时,如果每输入一下,CPU都100%一下,3, ...
- datagridview 点击列标题排序
开发winform中,平时经常用到数据列表,我们大多选用datagridview,但是此控件本身没有排序的功能.参阅网上资料.留下标记,以后备用. datagridview的数据显示一般是通过数据绑定 ...
- HTTP协议header标头详解
本文根据RFC2616(HTTP/1.1规范),参考 http://www.w3.org/Protocols/rfc2068/rfc2068 http://www.w3.org/Protocols/r ...
- excel设置下拉菜单,并且不同值会显示不同颜色
工作中常常要用的excel,每次都会有新的需求,然后不会,然后百度,然后过段时间可能就又忘了,于是就想说,自己记录下来~~~因为自己用的都是2010,其实哪个版本都差不多,都是应该可以找到相应的按钮滴 ...
- svn教程
安装过程: 1.下载软件后,双击程序进行安装,点击“Next”: 2.在许可证协议页面,选择“I Accept the terms in the License Agreement”,点击“Next” ...