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 ...
随机推荐
- pycharm永久激活记录
由于上一年安装的pycharm激活时是用的激活码,有期限的,一直到今年5月4日过期,这两天顺便把版本也更新到最新,一直用的free版,到今天提醒我free快到期了,所以才狠下心来去找解决方案,目前已经 ...
- python练手习题
不断记录python常见习题,不断寻求更多更好的解决办法.持续更新中..... 练习: 1. list两两元素交换位置,如[1,2,3,4,5,6] 执行后为 -> [2,1,4,3,6,5] ...
- Darwin's Letter【达尔文的信】
Darwin's Letter A letter written by Charles Darwin in 1875 has been returned to the Smithsonian Inst ...
- A1075 PAT Judge (25)(25 分)
A1075 PAT Judge (25)(25 分) The ranklist of PAT is generated from the status list, which shows the sc ...
- UVa 1649 Binomial coefficients 数学
题意: \(C(n, k) = m(2 \leq m \leq 10^{15})\),给出\(m\)求所有可能的\(n\)和\(k\). 分析: 设\(minK = min(k, n - k)\),容 ...
- TCP/IP网络编程之基于UDP的服务端/客户端
理解UDP 在之前学习TCP的过程中,我们还了解了TCP/IP协议栈.在四层TCP/IP模型中,传输层分为TCP和UDP这两种.数据交换过程可以分为通过TCP套接字完成的TCP方式和通过UDP套接字完 ...
- Java web学习总结
javaweb学习总结(十四)——JSP原理 孤傲苍狼 2014-07-24 09:38 阅读:46603 评论:37 JavaWeb学习总结(十三)——使用Session防止表单重复提交 孤 ...
- nsfwjs鉴黄识别最小化案例
3个月前,也就是2月份左右吧,Github上出现一个开源项目: Infinite Red, Inc.工作室宣布开源旗下基于tensorflow的tfjs的鉴黄小工具 据说是从15000张图片中 进行机 ...
- python字符串内置用法,择选重要
- 纸上得来终觉浅,绝知此事要躬行——Spring boot任务调度
前言:之前今日开讲项目的时候,用到了Quartz进行任务调度.后来做一个电商项目的时候,还用到了Quartz任务调度. 觉得挺简单的,a peace of cake. 忽略了总结,当时闭着眼睛都能捉 ...