HDU
来源:互联网 发布:怎么做数据分析报告 编辑:程序博客网 时间:2024/06/04 00:02
In the Kingdom of Black and White (KBW), there are two kinds of frogs: black frog and white frog.
NowN Input First line contains an integer T , which indicates the number of test cases.
Every test case only contains a string with lengthN , including only 0 (representing
a black frog) and1 (representing a white frog).
⋅ 1≤T≤50 .
⋅ for 60% data, 1≤N≤1000 .
⋅ for 100% data, 1≤N≤105 .
⋅ the string only contains 0 and 1. Output For every test case, you should output " Case #x: y",where x indicates the case number and counts from 1 and y is the answer. Sample Input Sample Output
Now
frogs are standing in a line, some of them are black, the others are white. The total strength of those frogs are calculated by dividing the line into minimum parts, each part should still be continuous, and can only contain one kind of frog. Then the strength is the sum of the squared length for each part.
However, an old, evil witch comes, and tells the frogs that she will change the color ofat most one frog and thus the strength of those frogs might change.
The frogs wonder the maximum possible strength after the witch finishes her job.
However, an old, evil witch comes, and tells the frogs that she will change the color ofat most one frog and thus the strength of those frogs might change.
The frogs wonder the maximum possible strength after the witch finishes her job.
Every test case only contains a string with length
a black frog) and
20000110101
Case #1: 26Case #2: 10
题意就是给出一个01串每次只能改变以为,相同数字组成一个区域,求每个区域大小平方的和最大
思路:输入的时候先把每个区间的大小统计一遍,然后暴力跑一边修改就能过
#include <iostream>#include <cstdio>#include <cmath>#include <cstdio>#include <algorithm>#include <cstring>#include <queue>#include <vector>#define inf 0x3f3f3f3fusing namespace std;char str[110000];int s[110000];int main(){ios::sync_with_stdio(false);long long int t, n, i;long long int m, x = 1;long long int mm, ss;long long int sum;cin>>t;while(t--){cin>>str;n = strlen(str);m = 0;mm = 0;sum = 0;for(i = 1;i <= n;i++){mm++;if(str[i] != str[i-1]){s[m++] = mm;sum += (mm * mm);mm = 0;}}mm = sum;for(i = 1;i < m;i++){ss = sum - s[i] * s[i] - s[i-1] * s[i-1];ss = ss + (s[i]+1) * (s[i]+1) + (s[i-1] -1) * (s[i-1]-1);mm = max(ss,mm);ss = sum - s[i] * s[i] - s[i-1] * s[i-1];ss = ss + (s[i]-1)*(s[i]-1) + (s[i-1]+1)*(s[i-1]+1);mm = max(ss,mm);if(s[i] == 1 && i + 1 < m){ss = sum - s[i-1] * s[i-1] -s[i] * s[i] - s[i+1] * s[i+1];ss = ss + (s[i-1] + s[i] + s[i+1]) * (s[i-1] + s[i] + s[i+1]);mm = max(mm,ss);}}cout<<"Case #"<<x<<": "<<mm<<endl;x++;}return 0;}
阅读全文
0 0
- hdu
- hdu
- HDU
- hdu ()
- hdu
- hdu
- HDU
- HDU
- hdu
- hdu
- HDU
- Hdu
- hdu
- hdu-
- hdu
- hdu
- hdu
- HDU
- 曾获ACM世界冠军,打造百度AI大脑,这位80后科学家要让AI人人可用
- android应用层服务——binderService,StartService,aidl,本地服务和远程服务
- word2007每次打开都要配置
- js获取URL中参数信息
- HashMap解析
- HDU
- 使用Shell编写猜数字的小游戏
- 简单的取表单数据的方法serializeArray
- python安装到eclipse-安装 PyDev
- 这个接口你知道吗?
- python空格与制表符
- Matchmaker
- 计算机IO概述
- C 语言 右左法则 (1)