UVA 1330 LA 3029 seerc 2004 - City Game
2014-03-08 18:43
281 查看
Bob is a strategy game programming specialist. In his new city building game thegaming environment is as follows: a city is built up by areas, in which there are streets, trees,factories and buildings. There is still some space
in the area that is unoccupied. The strategictask of his game is to win as much rent money from these free spaces. To win rent money youmust erect buildings, that can only be rectangular, as long and wide as you can. Bob is trying tofind a way to build the
biggest possible building in each area. But he comes across someproblems � he is not allowed to destroy already existing buildings, trees, factories and streets inthe area he is building in.
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. Eachone 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 markedwith the symbol F.
M<=1000 and width N<=1000, separated bya blank space. The next M lines contain N symbols that mark the reserved or free grid units,separated by a blank space. The symbols used are:
R � reserved unit
F � free unit
In the end of each area description there is a separating line.
题目大意:给定N*M的矩阵,其中一些格子是空地(F),其他是障碍(R)。求全部又空地组成的最大矩阵,结果×3.
用三个数组记录递推一个格子往上,往左,往右的障碍格位置。全部扫描一遍即可。
in the area that is unoccupied. The strategictask of his game is to win as much rent money from these free spaces. To win rent money youmust erect buildings, that can only be rectangular, as long and wide as you can. Bob is trying tofind a way to build the
biggest possible building in each area. But he comes across someproblems � he is not allowed to destroy already existing buildings, trees, factories and streets inthe area he is building in.
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. Eachone 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 markedwith the symbol F.
Input
The first line of the input file contains an integer K � determining the number ofdatasets. Next lines contain the area descriptions. One description is defined in the followingway: The first line contains two integers-area lengthM<=1000 and width N<=1000, separated bya blank space. The next M lines contain N symbols that mark the reserved or free grid units,separated by a blank space. The symbols used are:
R � reserved unit
F � free unit
In the end of each area description there is a separating line.
Output
For each data set in the input file print on a separate line, on the standard output, theinteger that represents the profit obtained by erecting the largest building in the area encoded bythe data set.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
题目大意:给定N*M的矩阵,其中一些格子是空地(F),其他是障碍(R)。求全部又空地组成的最大矩阵,结果×3.
用三个数组记录递推一个格子往上,往左,往右的障碍格位置。全部扫描一遍即可。
#include <cstdio> #include <iostream> #include <vector> #include <algorithm> #include <string> #include <cstring> #include <map> #include <cmath> #include <string> #include <queue> #include <set> using namespace std; #ifdef WIN typedef __int64 LL; #define iform "%I64d" #define oform "%I64d\n" #else typedef long long LL; #define iform "%lld" #define oform "%lld\n" #endif #define S64I(a) scanf(iform, &(a)) #define P64I(a) printf(oform, (a)) const int INF = 0x3f3f3f3f; const int maxn = 1000 + 50; int gleft[maxn][maxn]; int gright[maxn][maxn]; int up[maxn][maxn]; int G[maxn][maxn]; int main() { int kase; scanf("%d", &kase); while(kase--) { int n, m; scanf("%d%d", &n, &m); for(int i=0; i<n; i++) { for(int j=0; j<m; j++) { char ch = getchar(); while(ch!='F' && ch!='R') ch = getchar(); G[i][j] = ch == 'F' ? 0 : 1; } } int ans = 0; int lo=-1; for(int i=0; i<m; i++) { up[0][i] = -1 + G[0][i]; if(G[0][i]) lo = i; gleft[0][i] = lo; } int ro=m; for(int i=m-1; i>=0; i--) { if(G[0][i]) ro = i; gright[0][i] = ro; int w = gright[0][i] - gleft[0][i] - 1; int h = 0 - up[0][i]; if(w > 0 && h > 0) { int t = w * h; if(t > ans) { ans = t; } } } for(int i=1; i<n; i++) { lo = -1; for(int j=0; j<m; j++) { up[i][j] = G[i][j] ? i : up[i-1][j]; if(G[i][j]) lo = j; if(G[i-1][j]) { gleft[i][j] = lo; } else { gleft[i][j] = max(lo, gleft[i-1][j]); } } ro = m; for(int j=m-1; j>=0; j--) { if(G[i][j]) ro = j; if(G[i-1][j]) { gright[i][j] = ro; } else { gright[i][j] = min(ro, gright[i-1][j]); } int w = gright[i][j] - gleft[i][j] - 1; int h = i - up[i][j]; if(w>0 && h>0) { int t = w * h; if(t > ans) { ans = t; } } } } printf("%d\n", ans*3); } return 0; }
相关文章推荐
- linux RM删除文件,磁盘空间没有释放
- C++析构函数为什么要为虚函数
- 字母大小写转换并倒序输出
- 张国祥老师应邀在大庆油田天然气公司讲授制度建设与流程管理课程
- 构造函数私有化---单例模式
- [ACM] hdu 1201 18岁生日
- 通过反射跟踪JVM的运行时状态
- [ACM] hdu 1201 18岁生日
- <PY>今天研究了一下批处理,py拖动生成单文件exe
- c++ 多线程
- 怎样判断一个数是回文数
- imagemagick
- POJ 1815 最小点割集
- HDU 4059 The Boss on Mars 解题报告(4次方和+质因子分解+逆元+容斥原理)
- c++多线程学习
- 黑马程序员之java语言,及环境搭建
- 史上最详细的vsftpd配置文件讲解
- Xpose
- 稀疏矩阵Compressed Row Storage存储格式
- editplus的注册码