悬线法可解,稍有点烦琐。

#include <iostream>
#include <cstdio>
#include <cstring>
#include <string.h>
using namespace std; char map[1010][1010];
int lefts[1010][1010],heights[1010][1010],rights[1010][1010]; int CountSingle(int n,int m,char sing){
int ret=0;
for(int i=1;i<=n;i++){
if(i==1){
int l=0;
for(int j=1;j<=m;j++){
if(map[i][j]!=sing){
heights[i][j]=0;
lefts[i][j]=m+1;
l=j;
}
else{
heights[i][j]=1;
lefts[i][j]=l+1;
}
}
int r=m+1;
for(int j=m;j>=1;j--){
if(map[i][j]!=sing){
rights[i][j]=0;
r=j;
}
else{
rights[i][j]=r-1;
ret=max(ret,heights[i][j]*2+2*(rights[i][j]-lefts[i][j]+1));
}
}
}
else{
int l=0;
for(int j=1;j<=m;j++){
if(map[i][j]!=sing){
heights[i][j]=0;
lefts[i][j]=m+1;
l=j;
}
else{
if(map[i-1][j]==sing){
heights[i][j]=heights[i-1][j]+1;
lefts[i][j]=max(lefts[i-1][j],l+1);
}
else{
heights[i][j]=1;
lefts[i][j]=l+1;
}
}
}
int r=m+1;
for(int j=m;j>=1;j--){
if(map[i][j]!=sing){
rights[i][j]=0;
r=j;
}
else{
if(map[i-1][j]==sing){
rights[i][j]=min(rights[i-1][j],r-1);
ret=max(ret,heights[i][j]*2+2*(rights[i][j]-lefts[i][j]+1));
}
else{
rights[i][j]=r-1;
ret=max(ret,heights[i][j]*2+2*(rights[i][j]-lefts[i][j]+1));
}
}
}
}
}
return ret;
} int CountCross(int n,int m){
int ret=0;
for(int i=1;i<=n;i++){
if(i==1){
int l=0;
for(int j=1;j<=m;j++){
if(j==1){
heights[i][j]=1;
lefts[i][j]=1;
}
else{
if(map[i][j-1]==map[i][j]){
lefts[i][j]=j;
l=j-1;
heights[i][j]=1;
}
else{
lefts[i][j]=l+1;
heights[i][j]=1;
}
}
}
int r=m+1;
for(int j=m;j>=1;j--){
if(j==m){
heights[i][j]=1;
rights[i][j]=m;
}
else{
if(map[i][j]==map[i][j+1]){
heights[i][j]=1;
rights[i][j]=j;
r=j+1;
}
else{
rights[i][j]=r-1;
heights[i][j]=1;
}
}
ret=max(ret,heights[i][j]*2+2*(rights[i][j]-lefts[i][j]+1));
}
}
else{
int l=0;
for(int j=1;j<=m;j++){
if(j==1){
if(map[i][j]!=map[i-1][j]){
heights[i][j]=heights[i-1][j]+1;
lefts[i][j]=1;
}
else{
heights[i][j]=1;
lefts[i][j]=1;
}
}
else{
if(map[i][j]!=map[i-1][j]){
heights[i][j]=heights[i-1][j]+1;
if(map[i][j]==map[i][j-1]){
lefts[i][j]=j;
l=j-1;
}
else{
lefts[i][j]=max(lefts[i-1][j],l+1);
}
}
else{
heights[i][j]=1;
if(map[i][j]==map[i][j-1]){
lefts[i][j]=j;
l=j-1;
}
else{
lefts[i][j]=l+1;
}
}
}
}
int r=m+1;
for(int j=m;j>=1;j--){
if(j==m){
if(map[i][j]!=map[i-1][j]){
heights[i][j]=heights[i-1][j]+1;
rights[i][j]=m;
}
else{
heights[i][j]=1;
rights[i][j]=m;
}
}
else{
if(map[i][j]!=map[i-1][j]){
heights[i][j]=heights[i-1][j]+1;
if(map[i][j]==map[i][j+1]){
rights[i][j]=j;
r=j+1;
}
else{
rights[i][j]=min(rights[i-1][j],r-1);
}
}
else{
heights[i][j]=1;
if(map[i][j]==map[i][j+1]){
rights[i][j]=j;
r=j+1;
}
else{
rights[i][j]=r-1;
}
}
}
ret=max(ret,heights[i][j]*2+2*(rights[i][j]-lefts[i][j]+1));
}
}
}
return ret;
} int main(){
int ansR,ansB,ansC,kase=0;
int T,n,m;
scanf("%d",&T);
while(T--){
scanf("%d%d",&n,&m);
getchar();
for(int i=1;i<=n;i++)
gets(map[i]+1);
ansR=CountSingle(n,m,'R');
ansB=CountSingle(n,m,'B');
ansC=CountCross(n,m);
/* for(int i=1;i<=3;i++){
for(int j=1;j<=3;j++)
cout<<heights[i][j]<<' ';
cout<<endl;
}
cout<<endl;
for(int i=1;i<=3;i++){
for(int j=1;j<=3;j++)
cout<<lefts[i][j]<<' ';
cout<<endl;
}
cout<<endl;
for(int i=1;i<=3;i++){
for(int j=1;j<=3;j++)
cout<<rights[i][j]<<' ';
cout<<endl;
}
cout<<ansC<<endl;*/
cout<<"Case #"<<++kase<<": "<<max(ansR,max(ansB,ansC))<<endl;
}
return 0;
}

  

HDU 4328 Contest 3的更多相关文章

  1. HDU 5045 Contest(状压DP)

    Problem Description In the ACM International Collegiate Programming Contest, each team consist of th ...

  2. hdu - 5045 - Contest(国家压缩dp)

    意甲冠军:N个人M通过主打歌有自己的期望,每个问题发送人玩.它不能超过随机播放的次数1,追求最大业绩预期 (1 ≤ N ≤ 10,1 ≤ M ≤ 1000). 主题链接:pid=5045" ...

  3. [ACM] hdu 5045 Contest (减少国家Dp)

    Contest Problem Description In the ACM International Collegiate Programming Contest, each team consi ...

  4. HDU 4328 Cut the cake

    Cut the cake Time Limit: 6000/3000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others)Tota ...

  5. HDU–5988-Coding Contest(最小费用最大流变形)

    Coding Contest Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others)To ...

  6. hdu 5045 Contest(状态压缩DP)

    题解:我们使用一个二位数组dp[i][j]记录进行到第i个任务时,人组合为j时的最大和(这里的j我们用二进制的每位相应一个人). 详细见代码: #include <iostream> #i ...

  7. HDU 5045 Contest

    pid=5045">主题链接~~> 做题感悟:比赛时这题后来才写的,有点小尴尬.两个人商议着写写了非常久才写出来,I want to Powerful ,I believe me ...

  8. HDU 4335 Contest 4

    利用降幂公式..呃,还是自己去搜题解吧.知道降幂公式后,就不难了. #include <iostream> #include <cstdio> #include <alg ...

  9. HDU 4339 Contest 4

    树状数组,主要是抓住要求连续1的个数.这样,初始时,相同的加1,不同的加0. 查询时,用二分搜索右边界.就是比较当前mid-l+1的值与他们之间1的个数(这可以通过树状数组求区间和得出),记录右边界即 ...

随机推荐

  1. Java n个线程轮流打印数字的问题

    一. 实现两个线程.轮流打印出数字.例如以下: bThread --> 10 aThread --> 9 bThread --> 8 aThread --> 7 bThread ...

  2. iOS 打印出视图中全部的子视图的名称

    使用递归: - (void)listSubviewsOfView:(UIView *)view { // Get the subviews of the view NSArray *subviews ...

  3. 虚拟ONVIF 摄像机

    測试视频监控系统须要大量的Camera.搭建起来也很麻烦,在vdceye中增加虚拟onvif 摄像 机支持,把一个Camera变成上百个. watermark/2/text/aHR0cDovL2Jsb ...

  4. js 数组克隆

    在JS中,对于对象类型的变量的引用是通过类似C之类的"指针"的方式来操作的,及假设多个变量引用同一个对象,则随意一个变量对对象的操作都会影响到其他的变量. 这个可能不是非常明确,以 ...

  5. Android获取系统时间的多种方法

    Android中获取系统时间有多种方法,可分为Java中Calendar类获取,java.util.date类实现,还有android中Time实现. 现总结如下: 方法一: ? 1 2 3 4 5 ...

  6. NEU 1664 传送(最短路基础 堆优化Dijkstra)

    题目描述 小A最近喜欢上一款游戏:游戏把地图分了一些区域,这些区域可能会重叠,也可能不会. 游戏中有一项传送技能,改传送技能只能将在同一区域的两个地方使用.小A可以利用区域中重叠部分来实现从某一区域到 ...

  7. Python笔记(四)

    # -*- coding:utf-8 -*- # 控制语句 # if...else... print "********************1********************** ...

  8. C# WebAPI小记

    新建WebAPI项目 新建一个Model 安装Entity Framework 添加连接字符串 去Web.config 中 <configuration> 节点中最下面添加 在Word中编 ...

  9. shopping car 3.0

    #!/usr/bin/env python# -*- coding: utf-8 -*-# @File : 购物车3.0.py# @Author: Anthony.waa# @Date : 2018/ ...

  10. xbox 相关

    https://live.xbox.com/zh-CN/avatareditor xboxgames://