题目链接: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(暴力)的更多相关文章

  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 ...

  2. 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 ...

  3. 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 ...

  4. 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 ...

  5. HDU5583 Kingdom of Black and White

    Kingdom of Black and White Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/65536 K (Ja ...

  6. HDU 5583 Kingdom of Black and White(暴力)

    http://acm.hdu.edu.cn/showproblem.php?pid=5583 题意: 给出一个01串,现在对这串进行分组,连续相同的就分为一组,如果该组内有x个数,那么就对答案贡献x* ...

  7. HDU-5583-Kingdom of Black and White(2015ACM/ICPC亚洲区上海站-重现赛)

    Kingdom of Black and White                                                                           ...

  8. 2015ACM/ICPC亚洲区上海站

    5573 Binary Tree(构造) 题意:给你一个二叉树,根节点为1,子节点为父节点的2倍和2倍+1,从根节点开始依次向下走k层,问如何走使得将路径上的数进行加减最终结果得到n. 联想到二进制. ...

  9. 「WC2018」即时战略

    「WC2018」即时战略 考虑对于一条链:直接随便找点,然后不断问即可. 对于一个二叉树,树高logn,直接随便找点,然后不断问即可. 正解: 先随便找到一个点,问出到1的路径 然后找别的点,考虑问出 ...

随机推荐

  1. 【BZOJ】【3004】吊灯

    思路题 要将整棵树分成大小相等的连通块,那么首先我们可以肯定的是每块大小x一定是n的约数,且恰好分成$\frac{n}{x}$块,所以我有了这样一个思路:向下深搜,如果一个节点的size=x,就把这个 ...

  2. Swift-2-基本操作符

    // Playground - noun: a place where people can play import UIKit // 基本运算符 // 运算符有3种: 单目运算符(如 -a),二目运 ...

  3. Win32 Plus Extra Height of Caption Bar

    you set the size of the non-client area by handling the WM_NCCALCSIZE message. But don't do this unl ...

  4. HTTP协议中的5类状态码

    ①   客户方错误      100   继续      101   交换协议     ②   成功      200    OK      201    已创建      202   接收      ...

  5. ARM系列产品

    ARM7系列 ARM9系列 ARM9E系列 ARM10E系列 SecurCore系列 Intel的StrongARM ARM11系列 Intel的Xscale 其中,ARM7.ARM9.ARM9E和A ...

  6. Flex +WebService

    <?xml version="1.0" encoding="utf-8"?> <mx:Application xmlns:mx="h ...

  7. DllImport 相关错误

    问题: 当我用 [DllImport("*.dll", EntryPoint = "*",CallingConvention = CallingConventi ...

  8. Xamarin for Visual Studio 3.11.666 Beta版 破解补丁

    注意:本版本是 Beta 版   现已推送到稳定频道 前提概要 全新安装请参考 安装 Xamarin for Visual Studio. 最新稳定版请参考 Xamarin for Visual St ...

  9. QTP10.0安装说明

    QTP10.0 安装手册 注:安装之前检查清理相关注册表:运行->regdit-HKEY_LOCAL_MACHINE->HKEY_LOCAL_MACHINE\SOFTWARE->HK ...

  10. Android Non-UI to UI Thread Communications(Part 1 of 5)

    original:http://www.intertech.com/Blog/android-non-ui-to-ui-thread-communications-part-1-of-5/ ANDRO ...