[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的路径 然后找别的点,考虑问出 ...
随机推荐
- ajax 乱码
1. 在页面的中文变量前添加encodeURIComponent() $.ajax({ type: "POST", url: "", data:{ id:e ...
- 可执行文件(ELF)格式之讲解
ELF(Executable and Linking Format)是一种对象文件的格式,用于定义不同类型的对象文件(Object files)中都放了什么东西.以及都以什么样的格式去放这些东西.它自 ...
- Maven在项目中的应用
http://192.168.0.253:8081/nexus/#view-repositories;thirdparty~uploadPanel 使用局域网搭建的环境,输入用户名和密码登录,上传ja ...
- Map:比较新增加日期的和需要删除的日期 使用方法
1.场景描述:根据在日历选择的日期,数据库来保持我们选择日期. 2.方法,硬删除的方法,每次全部删除,然后再重新添加选择的新的日期.这样导致如果需要保存create_time的情况,那么每次操作的都是 ...
- POJ 2039
#include<iostream> #include<stdio.h> #include<string> #define MAXN 20 using namesp ...
- VS2010中出现无法嵌入互操作类型
针对word或excel操作时,出现VS2010中,无法嵌入互操作类型“……”,请改用适用的接口的解决方法 问了度娘,解决方法如出一辙:选中项目中引入的dll,鼠标右键,选择属性,把“嵌入互操作类型” ...
- http协议本身能获取客户端Mac地址问题
http 位于网络应用程 应用层 会话层 表示层 传输层 网络层 数据链路层 物理层 数据在最高层开始传输 没经历下面一层加一层的头,然后传入目的电脑再进行一层层的解刨,所以http本来没有mac而接 ...
- (转)【移动开发】Android中三种超实用的滑屏方式汇总(ViewPager、ViewFlipper、ViewFlow)
转自: http://smallwoniu.blog.51cto.com/3911954/1308959 现如今主流的Android应用中,都少不了左右滑动滚屏这项功能,(貌似现在好多人使用智能机都习 ...
- 编程实现LINUX下目录的层层遍历
/************************************************************************* > File Name: treedir.c ...
- iis 重启 (三种方法)
iis 重启 (三种方法) WINDOWS提供WEB服务的IIS有时候会出现访问过大导致网站打不开,这时重启IIS是最好的选择. 方法/步骤 1 1.界面操作 打开“控制面板”->“管理工具”- ...