poj 1964 City Game
Each area has its width and length. The area is divided into a grid of equal square units.The rent paid for each unit on which you're building stands is 3$.
Your task is to help Bob solve this problem. The whole city is divided into K areas. Each one of the areas is rectangular and has a different grid size with its own length M and width N.The existing occupied units are marked with the symbol R. The unoccupied units are marked with the symbol F.
Input
R – reserved unit
F – free unit
In the end of each area description there is a separating line.
Output
Sample Input
2
5 6
R F F F F F
F F F F F F
R R R F F F
F F F F F F
F F F F F F 5 5
R R R R R
R R R R R
R R R R R
R R R R R
R R R R R
Sample Output
45
0
#include<cstdio>
#include<iostream>
//#include<cstring>
//include<algorithm>
//#include<cmath>
//#include<vector>
//#include<queue>
//#include<set>
#define INF 0x3f3f3f3f
#define N 1005
#define re register
#define Ii inline int
#define Il inline long long
#define Iv inline void
#define Ib inline bool
#define Id inline double
#define ll long long
#define Fill(a,b) memset(a,b,sizeof(a))
#define R(a,b,c) for(register int a=b;a<=c;++a)
#define nR(a,b,c) for(register int a=b;a>=c;--a)
#define Min(a,b) ((a)<(b)?(a):(b))
#define Max(a,b) ((a)>(b)?(a):(b))
#define Cmin(a,b) ((a)=(a)<(b)?(a):(b))
#define Cmax(a,b) ((a)=(a)>(b)?(a):(b))
#define D_e(x) printf("\n&__ %d __&\n",x)
#define D_e_Line printf("-----------------\n")
#define D_e_Matrix for(re int i=1;i<=n;++i){for(re int j=1;j<=m;++j)printf("%d ",g[i][j]);putchar('\n');}
using namespace std;
//The Code Below Is Bingoyes's Function Forest.
Ii read(){
int s=,f=;char c;
for(c=getchar();c>''||c<'';c=getchar())if(c=='-')f=-;
while(c>=''&&c<='')s=s*+(c^''),c=getchar();
return s*f;
}
Iv print(ll x){
if(x<)putchar('-'),x=-x;
if(x>)print(x/);
putchar(x%^'');
}
/*
Iv Floyd(){
R(k,1,n)
R(i,1,n)
if(i!=k&&dis[i][k]!=INF)
R(j,1,n)
if(j!=k&&j!=i&&dis[k][j]!=INF)
Cmin(dis[i][j],dis[i][k]+dis[k][j]);
}
Iv Dijkstra(int st){
priority_queue<int>q;
R(i,1,n)dis[i]=INF;
dis[st]=0,q.push((nod){st,0});
while(!q.empty()){
int u=q.top().x,w=q.top().w;q.pop();
if(w!=dis[u])continue;
for(re int i=head[u];i;i=e[i].nxt){
int v=e[i].pre;
if(dis[v]>dis[u]+e[i].w)
dis[v]=dis[u]+e[i].w,q.push((nod){v,dis[v]});
}
}
}
Iv Count_Sort(int arr[]){
int k=0;
R(i,1,n)
++tot[arr[i]],Cmax(mx,a[i]);
R(j,0,mx)
while(tot[j])
arr[++k]=j,--tot[j];
}
Iv Merge_Sort(int arr[],int left,int right,int &sum){
if(left>=right)return;
int mid=left+right>>1;
Merge_Sort(arr,left,mid,sum),Merge_Sort(arr,mid+1,right,sum);
int i=left,j=mid+1,k=left;
while(i<=mid&&j<=right)
(arr[i]<=arr[j])?
tmp[k++]=arr[i++]:
(tmp[k++]=arr[j++],sum+=mid-i+1);//Sum Is Used To Count The Reverse Alignment
while(i<=mid)tmp[k++]=arr[i++];
while(j<=right)tmp[k++]=arr[j++];
R(i,left,right)arr[i]=tmp[i];
}
Iv Bucket_Sort(int a[],int left,int right){
int mx=0;
R(i,left,right)
Cmax(mx,a[i]),++tot[a[i]];
++mx;
while(mx--)
while(tot[mx]--)
a[right--]=mx;
}
*/
int a[N][N];ll s[N][N];
Il Maximum_Submatrix(int n,int m){
ll ans=;
R(i,,n)
R(j,,m){
char ch;
cin>>ch;
s[i][j]=s[i-][j]+s[i][j-]-s[i-][j-]+((ch=='F')?:-INF);//Matrix prefix sum.
}
R(i,,n)
R(j,i,n){
ll sum=;
R(k,,m)
Cmin(sum,s[j][k]-s[i-][k]),Cmax(ans,s[j][k]-s[i-][k]-sum);
}
return ans;
}
#define Outprint(x) print(x),putchar('\n');
int main(){
int T=read();
while(T--){
int n=read(),m=read();
ll ans=Maximum_Submatrix(n,m);
ans*=;//Convert area to money.
Outprint(ans);
}
return ;
}
/*
Note:
Get the maximum submatrix as the area.
Error:
Rember to add 'return'(especially in 'inline long long').
*/
poj 1964 City Game的更多相关文章
- 离散化+线段树  POJ 3277 City Horizon
		POJ 3277 City Horizon Time Limit: 2000MS Memory Limit: 65536K Total Submissions: 18466 Accepted: 507 ... 
- 【POJ 1964】 City Game
		[题目链接] http://poj.org/problem?id=1964 [算法] 记f[i]表示第i行最多向上延伸的行数 然后,对于每一行,我们用单调栈计算出这一行向上延伸的最大矩形面积,取最大值 ... 
- POJ 1964&HDU 1505&HOJ 1644 City Game(最大0,1子矩阵和总结)
		最大01子矩阵和,就是一个矩阵的元素不是0就是1,然后求最大的子矩阵,子矩阵里的元素都是相同的. 这个题目,三个oj有不同的要求,hoj的要求是5s,poj是3秒,hdu是1秒.不同的要求就对应不同的 ... 
- poj 3277 City Horizon (线段树 扫描线 矩形面积并)
		题目链接 题意: 给一些矩形,给出长和高,其中长是用区间的形式给出的,有些区间有重叠,最后求所有矩形的面积. 分析: 给的区间的范围很大,所以需要离散化,还需要把y坐标去重,不过我试了一下不去重 也不 ... 
- POJ 2312Battle City(BFS-priority_queue 或者是建图spfa)
		/* bfs搜索!要注意的是点与点的权值是不一样的哦! 空地到空地的步数是1, 空地到墙的步数是2(轰一炮+移过去) 所以用到优先队列进行对当前节点步数的更新! */ #include<iost ... 
- POJ 3277 City Horizon(扫描线+线段树)
		题目链接 类似求面积并..2Y.. #include <cstdio> #include <cstring> #include <string> #include ... 
- [POJ]  3277  .City Horizon(离散+线段树)
		来自这两篇博客的总结 http://blog.csdn.net/SunnyYoona/article/details/43938355 http://m.blog.csdn.net/blog/mr_z ... 
- POJ  3277  City Horizon(叶子节点为[a,a+1)的线段树+离散化)
		网上还有用unique函数和lowerbound函数离散的方法,可以百度搜下题解就有. 这里给出介绍unique函数的链接:http://www.cnblogs.com/zhangshu/archiv ... 
- POJ 3277 City Horizon
		标题效果: 每间房子的长度给出阴影(在间隔代表)而高度,求阴影总面积. 解题思路:矩形面积并. 以下是代码: #include <set> #include <map> #in ... 
随机推荐
- oracle级联更新与级联删除
			Oracle级联删除:可以使用外键约束来实现,建立表的主外键关系,给列设置级联删除.如下: ——创建了CLASS表,并设置ID字段为主键. -- Create tablecreate table CL ... 
- Linux3基本命令 ls,pwd,cat,echo,mv,cp,mkdir,rm,ln
			ls 列出文件名称. -l 列出长文件名称. -rwxr-xr-- 1 root root 10739 Dec 23 13:31 bbscon (7) (4) (5) (6) ... 
- 2-javascript::笔记
			0.位置: HTML 中的脚本必须位于 <script> 与 </script> 标签之间. 脚本可被放置在 HTML 页面的 <body> 和 <head& ... 
- 面试题:try,catch,finally都有return语句时执行哪个 已看1
			1.不管有木有出现异常,finally块中代码都会执行: return 先执行 把值临时存储起来, 执行完finally之后再取出来 值是不会改变的2.当try和catch中有return时,fina ... 
- Django ——Timezone 处理
			Django ——Timezone 处理 https://blog.csdn.net/qq_37049781/article/details/79347278 2018年02月22日 14:50:24 ... 
- Part4_lesson2---ARM处理器这个硬件启动流程分析
			1.启动方式 s3c2440:可以从Nor flash启动,Nor flash一般是2MB:也可以从Nandflash启动,它一般是256MB,我们习惯上把我们的uboot,内核以及文件系统都放到Na ... 
- html5操作类名API——classlist
			tagNode.classList.add('123'); // 添加类 tagNode.classList.remove('bbb'); // 删除类 tagNode.classList.toggl ... 
- javascript总结5:js常见的数据类型
			1 Number 数字类型 :包含正数,负数,小数 十进制表示: var n1 =23; 十六进制表示法:从0-9,a(A)-f(F)表示数字.以0x开头. var n2 = 0x42 2 字符串数据 ... 
- (转)ASP.NET MVC4+EasyUI+EntityFrameWork权限管理系统——数据库的设计(一)
			原文地址:http://www.cnblogs.com/cmsdn/p/3371576.html 快一年没写博客了,这段时间感觉好迷茫,写点博客,记录一下自己的成长过程,希望对大家也有帮助 先上图 一 ... 
- 常用Linux命令:mount/umount/blkid
			一.mount:挂载命令 1.命令格式 mount [参数] [设备名称] [挂载点] 2.常用参数 -a :安装在/etc/fstab文件中列出的所有文件系统 -f :伪装mount,做出检 ... 
