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 ...
随机推荐
- 已解决: idea创建并部署SpringMVC项目时 报错 java.lang.ClassNotFoundException: org.springframework.web.context.ContextLoaderListener
用IDEA创建并运行SpringMVC项目时,最初发现没有Servlet包,这个问题已在上篇解决,然而当我们尝试去运行此时的SpringMVC项目时,发现仍然有错误.ClassNotFoundExce ...
- c 语言技巧
位运算 & 位逻辑与 | 位逻辑或 ^ 位逻辑异或 - 位逻辑反 >> 右移 << 左移 通过对数据本身的01编码进行处理,速度稍微快于普通运算符 如,10 / 2 = ...
- 7- vue django restful framework 打造生鲜超市 -商品类别数据展示(上)
Vue+Django REST framework实战 搭建一个前后端分离的生鲜超市网站 Django rtf 完成 商品列表页 并没有将列表页的数据json 与前端的页面展示结合起来 讲解如果将dr ...
- day 85 Vue学习七之vue-cookie
Vue学习七之vue-cookie 通过vue如何操作cookie呢 参考链接:https://www.jianshu.com/p/535b53989b39 第一步:安装vue-cookies ...
- A Bug's Life POJ - 2492 (带权并查集)
A Bug's Life POJ - 2492 Background Professor Hopper is researching the sexual behavior of a rare spe ...
- A计划 hdu2102(BFS)
A计划 hdu2102 可怜的公主在一次次被魔王掳走一次次被骑士们救回来之后,而今,不幸的她再一次面临生命的考验.魔王已经发出消息说将在T时刻吃掉公主,因为他听信谣言说吃公主的肉也能长生不老.年迈的国 ...
- Python中str、list、numpy分片操作
在Python里,像字符串(str).列表(list).元组(tupple)和这类序列类型都支持切片操作 对对象切片,s是一个字符串,可以通过类似数组索引的方式获取字符串中的字符,同时也可以用s[a: ...
- Git的安装及常用操作
一.Git的安装 1.下载Git,官网地址为:https://git-scm.com/downloads. 2.下载完成之后,双击目录进行安装 3.选择安装目录 4.选择组件,默认即可 5.设 ...
- go经典练习题涉及流程控制-字符串-struct-map的数据类型的处理
one:求1到100之间的质数 package main import ( "fmt" ) func isPrime(n int) bool { var flag = true f ...
- Python框架之Django学习笔记(五)
第一个Django网页小结 进来的请求转入/hello/. Django通过在ROOT_URLCONF配置来决定根URLconf. Django在URLconf中的所有URL模式中,查找第一个匹配/h ...