HDU 4328 Cut the cake
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
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?

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.
1 1
B
3 3
BBR
RBB
BBB
Case #2: 8
#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的更多相关文章
- HDU  4762  Cut the Cake(公式)
		Cut the Cake Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)Tota ... 
- 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 ... 
- HDU 4762 Cut the Cake(高精度)
		Cut the Cake Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)Tota ... 
- 【HDOJ】4328 Cut the cake
		将原问题转化为求完全由1组成的最大子矩阵.挺经典的通过dp将n^3转化为n^2. /* 4328 */ #include <iostream> #include <sstream&g ... 
- HDU 4762 Cut the Cake
		题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=4762 题目大意:将n个草莓随机放在蛋糕上,草莓被看做是点,然后将蛋糕平均切成m份,求所有草莓在同一块蛋 ... 
- hdu 4762 Cut the Cake概率公式
		题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=4762 题目大意:一个圆形蛋糕,现在要分成M个相同的扇形,有n个草莓,求n个草莓都在同一个扇形上的概率. ... 
- 2013长春网赛1004 hdu 4762 Cut the Cake
		题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=4762 题意:有个蛋糕,切成m块,将n个草莓放在上面,问所有的草莓放在同一块蛋糕上面的概率是多少.2 & ... 
- hdu 4762 Cut the Cake (大数乘法)
		猜公式: ans=n/m^(n-1) #include<stdio.h> #include<string.h> struct BigNum { ]; int len; }; i ... 
- HDU 2134 Cuts the cake
		http://acm.hdu.edu.cn/showproblem.php?pid=2134 Problem Description Ice cream took a bronze medal in ... 
随机推荐
- 二、MySQL 管理
			MySQL 管理 启动及关闭 MySQL 服务器 Windows 系统下 在 Windows 系统下,打开命令窗口(cmd),进入 MySQL 安装目录的 bin 目录. 启动: cd c:/mysq ... 
- content is king – Bill Gates (1/3/1996) 内容为王 - 比尔盖茨
			以下中文版本由谷歌翻译 内容为王 - 比尔盖茨(1/3/1996) 内容是我期望在互联网上赚取大部分真钱的地方,就像在广播中一样. 半个世纪前开始的电视革命催生了许多行业,包括制造电视机,但长期的赢家 ... 
- 绘制字符串:imagestring()
			<?php //1. 绘制图像资源(创建一个画布) $image = imagecreatetruecolor(500, 300); //2. 先分配一个绿色 $green = imagecol ... 
- C语言的位运算的优势 !
			位运算加速技巧1. 如果乘上一个2的倍数数值,可以改用左移运算(Left Shift) 加速 300% x = x * 2; x = x * 64; //改为: x = x << 1; / ... 
- 适合学习C语言开源项目——嵌入式脚本语言 Berry
			嵌入式脚本语言 Berry github网址 :https://github.com/Skiars/berry Berry 是一款面向小型嵌入式系统的脚本语言,目前发布了 0.1.0 版本.相比于其他 ... 
- [BZOJ1588]营业额统计(Splay)
			Description 题意:给定 n个数,每给定一个数,在之前的数里找一个与当前数相差最小的数,求相差之和(第一个数为它本身) 如:5 1 2 5 4 6 Ans=5+|1-5|+|2-1|+|5- ... 
- n个人排队都不站在原来的位置
			一.题目描述 有n个人首先站成一排,请问,当n个人第二次再重新排列,每个人都不在原来的位置上,问有多少种站法.例如,原来有3个人,ABC,那么第二次每个人都不在原来的位置上有2种站法,BCA和CAB, ... 
- (WPF&Silverlight)silverlight自定义控件
			2个半小时弄懂了自定义控件是怎么回事儿. 在silverlight中创建一个UserControl,把上面sliderbar的外观和功能都封装在里面. 以自定义控件mapslider控件为例: 1.首 ... 
- CSU 1326: The contest(分组背包)
			http://acm.csu.edu.cn/OnlineJudge/problem.php?id=1326 题意: n个题目,每个题目都有一个价值Pi和相对能力消耗Wi,但是有些题目因为太坑不能同时做 ... 
- P1194 买礼物(建模)
			P1194 买礼物 题目描述 又到了一年一度的明明生日了,明明想要买B样东西,巧的是,这B样东西价格都是A元. 但是,商店老板说最近有促销活动,也就是: 如果你买了第I样东西,再买第J样,那么就可以只 ... 
