hdu5583
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <math.h> char str[];
///注意在ans+=f[g]*f[g];中,ans是long long,所以运算的两个数至少有一个数是long long,所以f数组选择的类型是长整形
long long f[]; int main()
{
long n,g,pre,len,i,j;
long long ans,t,s;
scanf("%ld",&n);
for (j=;j<=n;j++)
{
g=;
pre=-;
ans=;
scanf("%s",str);
len=strlen(str);
for (i=;i<len;i++)
if (str[i]!=str[i+])
{
g++;
f[g]=i-pre;
ans+=f[g]*f[g];
pre=i;
}
if (g==)
printf("Case #%ld: %lld\n",j,ans);
else
{
t=;
for (i=;i<g;i++)
{
//(f[x]+1)*(f[x]+1)+(f[y]-1)*(f[y]-1)-f[x]*f[x]-f[y]*f[y]=2*f[x]-2*f[y]+2
s=abs(f[i]-f[i+]);
if (s>t)
t=s;
}
t=t*+;
for (i=;i<g;i++)
if (f[i]==)
{
s=(f[i-]++f[i+])*(f[i-]++f[i+])-f[i-]*f[i-]--f[i+]*f[i+];
if (s>t)
t=s;
}
printf("Case #%ld: %lld\n",j,ans+t);
}
}
return ;
}
hdu5583的更多相关文章
- 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 Kingdom of Black and White Time Limit: 2000/1000 ...
随机推荐
- 20155305《网络对抗》PC平台逆向破解(二)
20155305<网络对抗>PC平台逆向破解(二) shellcode注入 1.shellcode shellcode是一段代码,溢出后,执行这段代码能开启系统shell. 2.构造方法 ...
- 20155333 《网络对抗》 Exp8 Web基础
20155333 <网络对抗> Exp8 Web基础 基础问题 (1)什么是表单? 表单在网页中主要负责数据采集功能. 一个表单有三个基本组成部分: 表单标签,这里面包含了处理表单数据所用 ...
- 20155334 《网络攻防》Exp5 MSF基础应用
一.基础问题回答 解释exploit,payload,encode是什么: 项目 作用 exploit 是负载有用代码的交通工具,让代码到达目的地,并作用 payload 是有具体功能的代码,能够完成 ...
- 原生 JS 实现手机验证码倒计时
可以使用 pointer-events 来阻止元素成为鼠标事件的 target.html5 新增操作元素 class 类名的方式 classList. classList 方法 add(value): ...
- KNN算法的R语言实现
近邻分类 简言之,就是将未标记的案例归类为与它们最近相似的.带有标记的案例所在的类. 应用领域: 1.计算机视觉:包含字符和面部识别等 2.推荐系统:推荐受众喜欢电影.美食和娱乐等 3.基因工程:识别 ...
- MQ见解
MQ 消息队列是系统级.模块级的通信.RPC是对象级.函数级通信. 1) 什么是推模式,什么是拉模式 2) 有没有消息丢失情况,如何防止 3) MQ用来解决什么问题 4) 你们用的什么MQ,为什么要用 ...
- LeetCode 3Sum (Two pointers)
题意 Given an array S of n integers, are there elements a, b, c in S such that a + b + c = 0? Find all ...
- Redux系列x:源码解析
写在前面 redux的源码很简洁,除了applyMiddleware比较绕难以理解外,大部分还是 这里假设读者对redux有一定了解,就不科普redux的概念和API啥的啦,这部分建议直接看官方文档. ...
- Azure 基础:Queue Storage
Azure Storage 是微软 Azure 云提供的云端存储解决方案,当前支持的存储类型有 Blob.Queue.File 和 Table. 笔者在前文中介绍了 File Storage 的基本用 ...
- 微软职位内部推荐-Sr. SW Engineer for Privacy Id
微软近期Open的职位: Job posting title: Senior Software Engineer for Privacy Identification Profession: Engi ...