Cut the cake

Time Limit: 6000/3000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others)
Total Submission(s): 1250    Accepted Submission(s): 489

Problem Description:
Mark bought a huge cake, because his friend ray_sun’s birthday is coming. Mark is worried about how to divide the cake since it’s so huge and ray_sun is so strange. Ray_sun is a nut, you can never imagine how strange he was, is, and going to be. He does not eat rice, moves like a cat, sleeps during work and plays games when the rest of the world are sleeping……It is not a surprise when he has some special requirements for the cake. A considering guy as Mark is, he will never let ray_sun down. However, he does have trouble fulfilling ray_sun’s wish this time; could you please give him a hand by solving the following problem for him?
  The cake can be divided into n*m blocks. Each block is colored either in blue or red. Ray_sun will only eat a piece (consisting of several blocks) with special shape and color. First, the shape of the piece should be a rectangle. Second, the color of blocks in the piece should be the same or red-and-blue crisscross. The so called ‘red-and-blue crisscross’ is demonstrated in the following picture. Could you please help Mark to find out the piece with maximum perimeter that satisfies ray_sun’s requirements?
 
Input
The first line contains a single integer T (T <= 20), the number of test cases.
  For each case, there are two given integers, n, m, (1 <= n, m <= 1000) denoting the dimension of the cake. Following the two integers, there is a n*m matrix where character B stands for blue, R red.
Output
For each test case, output the cased number in a format stated below, followed by the maximum perimeter you can find.
Sample Input
2
1 1
B
3 3
BBR
RBB
BBB
Sample Output
Case #1: 4
Case #2: 8
Author
BJTU
Source
2012 Multi-University Training Contest 3
Recommend
zhoujiaqi2010   |   We have carefully selected several similar problems for you:  4321 4366 4335 4377 4371 
 #include<iostream>
#include<cstring>
#include<cstdio>
using namespace std;
#include<algorithm>
#define N 1010
int n,m,h[N][N],l[N][N],r[N][N];
char g[N][N];
int ans=,tmpl[N],tmpr[N];
void solve(char key){
memset(h,,sizeof(h));
memset(l,,sizeof(l));
memset(r,,sizeof(r));
int mx=;
for(int i=;i<=m;i++){
l[][i]=;r[][i]=m;
}
for(int i=;i<=n;i++){
int tmp=;
for(int j=;j<=m;j++){
if(g[i][j]!=key)tmp=j+;
else tmpl[j]=tmp;
}
tmp=m;
for(int j=m;j>=;j--){
if(g[i][j]!=key) tmp=j-;
else tmpr[j]=tmp;
}
//记录好了一个点能到达的 最左边 和最右边,
//接下来就是dp了
for(int j=;j<=m;j++){
if(g[i][j]!=key){
l[i][j]=;h[i][j]=;r[i][j]=m;
continue;
}
h[i][j]=h[i-][j]+;
l[i][j]=max(l[i-][j],tmpl[j]);
r[i][j]=min(r[i-][j],tmpr[j]);
mx=max(*(r[i][j]-l[i][j]++h[i][j]),mx);
}
}
ans=max(ans,mx);
}
int main()
{
int T,tt=;scanf("%d",&T);
for(int tz=;tz<=T;tz++){
ans=;
scanf("%d%d",&n,&m);
for(int i=;i<=n;i++)
scanf("%s",g[i]+);
solve('B');solve('R');
for(int i=;i<=n;i++)
for(int j=;j<=m;j++)
if((i+j)%==){
if(g[i][j]=='B')g[i][j]='R';
else g[i][j]='B';
}
solve('B');solve('R');
printf("Case #%d: ",tt++);
printf("%d\n",ans);
}
return ;
}

思路:悬线法~~~~DP求满足题意的最大子矩阵的边长

 

HDU 4328 Cut the cake的更多相关文章

  1. HDU 4762 Cut the Cake(公式)

    Cut the Cake Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)Tota ...

  2. HDU 4762 Cut the Cake (2013长春网络赛1004题,公式题)

    Cut the Cake Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)Tota ...

  3. HDU 4762 Cut the Cake(高精度)

    Cut the Cake Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)Tota ...

  4. 【HDOJ】4328 Cut the cake

    将原问题转化为求完全由1组成的最大子矩阵.挺经典的通过dp将n^3转化为n^2. /* 4328 */ #include <iostream> #include <sstream&g ...

  5. HDU 4762 Cut the Cake

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=4762 题目大意:将n个草莓随机放在蛋糕上,草莓被看做是点,然后将蛋糕平均切成m份,求所有草莓在同一块蛋 ...

  6. hdu 4762 Cut the Cake概率公式

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=4762 题目大意:一个圆形蛋糕,现在要分成M个相同的扇形,有n个草莓,求n个草莓都在同一个扇形上的概率. ...

  7. 2013长春网赛1004 hdu 4762 Cut the Cake

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=4762 题意:有个蛋糕,切成m块,将n个草莓放在上面,问所有的草莓放在同一块蛋糕上面的概率是多少.2 & ...

  8. hdu 4762 Cut the Cake (大数乘法)

    猜公式: ans=n/m^(n-1) #include<stdio.h> #include<string.h> struct BigNum { ]; int len; }; i ...

  9. HDU 2134 Cuts the cake

    http://acm.hdu.edu.cn/showproblem.php?pid=2134 Problem Description Ice cream took a bronze medal in ...

随机推荐

  1. SummerVocation_Learning--java的线程机制

    线程:是一个程序内部的执行路径.普通程序只有main()一条路径.如下列程序: import java.lang.Thread; //导入线程实现包 public class Test_Thread ...

  2. PHP 工厂模式介绍

    工厂模式,顾名思义,如同工厂一样,你把原材料放入工厂中,出来的是成品,而你并不需要知道工厂里做了什么.代码中也类似,把主要参数放入一个工厂里,返回的是处理好的数据,我们并不需要工厂里做了什么,只需要知 ...

  3. 将xml转为array 输出xml字符

    //将xml转为array private function fromXml($xml){ // 禁止引用外部xml实体 libxml_disable_entity_loader(true); ret ...

  4. mysql六:数据备份、pymysql模块

    一 IDE工具介绍 生产环境还是推荐使用mysql命令行,但为了方便我们测试,可以使用IDE工具 掌握: #1. 测试+链接数据库 #2. 新建库 #3. 新建表,新增字段+类型+约束 #4. 设计表 ...

  5. poj-3253 fence repair(贪心题)

    题目描述: Farmer John wants to repair a small length of the fence around the pasture. He measures the fe ...

  6. 笔记-python-lib-re

    笔记-python-lib-re 1.      re模块简介 re模块提供了与perl类似的正则匹配功能. 要搜索的模式和字符串都可以是Unicode字符串(str)以及8位字符串(bytes).但 ...

  7. 版本控制之GitHub — — 第一步的理解

    GitHub是时下最流行的版本控制的一门“技术”,此之前svn(subversion)也是同样的作用. 至于版本控制:Git是分布式的,而svn是中心式的(或者叫集中式的)版本控制系统,这是两者之间理 ...

  8. Java集合---List、Set、Iterator、Map简介

    1.List集合 1.1概念 List继承自Collection接口.List是一种有序集合,List中的元素可以根据索引(顺序号:元素在集合中处于的位置信息)进行取得/删除/插入操作. 跟Set集合 ...

  9. python3与django中@property详解

    django提供了内置装饰器 @staticmethod\@classmethod\property 在OSQA中,@property的使用频率是非常高的.下面就是它的使用方法: @property ...

  10. 网络安全巧设置 Win2008 R2 防火墙详解(1)

    针对一般中小企业型来说,如果希望对企业网络进行安全管理,不一定非得花高价钱购买专业的防火墙设置,直接借助操作系统本身自带的防火墙功能即可以满足一般企业的应用,今天我们就一起来探究一下Windows S ...