City Game

Time Limit:3000MS     Memory Limit:0KB     64bit IO Format:%lld & %llu

Submit Status

Description

Bob is a strategy game programming specialist. In his new city building game the gaming 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 strategic task of his game is to win as much rent money from these free spaces. To win rent money you must erect buildings, that can only be rectangular, as long and wide as you can. Bob is trying to find a way to build the biggest possible building in each area. But he comes across some problems – he is not allowed to destroy already existing buildings, trees, factories and streets in the 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. 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

The first line of the input file contains an integer K – determining the number of datasets. Next lines contain the area descriptions. One description is defined in the following way: The first line contains two integers-area length M<=1000 and width N<=1000, separated by a 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, the integer that represents the profit obtained by
erecting the largest building in the area encoded by the 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 算法解析:
扫描线模拟!
R F F F F F                 0 1 2 3 4 5
F F F F F F 1 2 3 4 5 6
R R R F F F ====》》》》0 0 0 1 2 3
F F F F F F 1 2 3 4 5 6
F F F F F F 1 2 3 4 5 6 R则为0, 连续的F则赋 1++ ;(这是有用的,其实可以判断连续的宽度)
#include <stdio.h>
#include <string.h> int map[1001][1001]; int main()
{
int t;
scanf("%d", &t );
int i, j, k;
int n, m;
char ch;
while(t--)
{
scanf("%d %d%*c", &n, &m );
memset(map, 0, sizeof(0)); //每次都得初始化
for(i=1; i<=n; i++)
{
for(j=1; j<=m; j++)
{
ch=getchar();
while(ch!='F' && ch!='R' )
{
ch=getchar();
}
if(ch=='F')
{
map[i][j] = map[i][j-1] + 1;
}
else
{
map[i][j] = 0;
}
}
} //map的创建,注意对字符与空格的处理,然后转化为数字存进map
//存数方式要注意
int min;
int area=0; //初始面积为0
int high; //定义高度
for(i=1; i<=n; i++)
{
for(j=1; j<=m; j++)
{
if(map[i][j]!=0) //访问的数据>0 : (F)
{
min=map[i][j] ;
if( area < map[i][j] )
{
area = map[i][j] ;
}
high =1; //初始高度自身
for(k=i-1; k>=1; k--)
{
if(map[k][j]==0 )
break;
else
{
high++; //高度增加
if(map[k][j] < min )
{
min = map[k][j] ;
}
if(area < high*min )
{
area = high*min;
}
}
}
}
}
}
printf("%d\n", area*3 );
}
return 0;
}

HDU 之 City Game的更多相关文章

  1. HDU 1505 City Game (hdu1506 dp二维加强版)

    F - City Game Time Limit:1000MS     Memory Limit:32768KB     64bit IO Format:%I64d & %I64u Submi ...

  2. HDU 3634 City Planning (离散化)

    City Planning Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)Tot ...

  3. hdu 3624 City Planning(暴力,也可扫描线)

    City Planning Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others) To ...

  4. HDU 5013 City Tour

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=5013 题意: 思路: 这里有错,是Hi(x)=sigama(Hji)(j属于x) const int ...

  5. HDU 1505 City Game(01矩阵 dp)

    Problem Description Bob is a strategy game programming specialist. In his new city building game the ...

  6. HDU 1505 City Game(DP)

    City Game Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others) Total ...

  7. HDU 1505 City Game

    这题是上一题的升级版 关键在于条形图的构造,逐行处理输入的矩阵,遇到'F'则在上一次的条形图基础上再加1,遇到'R'则置为0 然后用上一题的算法,求每行对应条形图的最大矩阵的面积. 另外:本来是deb ...

  8. HDU 1505 Largest Rectangle in a Histogram &amp;&amp; HDU 1506 City Game(动态规划)

    1506意甲冠军:给你一个连续的直方图(拼贴底部长度1).求连续基质区. 对每一个直方图,分别向左向右进行扩展. #include<cstdio> #include<stdlib.h ...

  9. HDU - 4496 City 逆向并查集

    思路:逆向并查集,逆向加入每一条边即可.在获取联通块数量的时候,直接判断新加入的边是否合并了两个集合,如果合并了说明联通块会减少一个,否则不变. AC代码 #include <cstdio> ...

随机推荐

  1. java中利用WeakHashMap实现缓存

    简介 WeakHashMap是Java集合框架里的一员,从名字可以看出它是某种 Map.它的特殊之处在于 WeakHashMap 里的entry可能会被GC自动删除,即使程序员没有调用remove() ...

  2. 定时执行线程池ScheduledExecutorService的使用

    ScheduledExecutorService progressExecutorService = Executors.newScheduledThreadPool(1); ScheduledFut ...

  3. WAS集群系列(3):集群搭建:步骤1:准备文件

    说明:"指示轨迹"为"点选顺序",截图为点击后效果截图 环境 项目点 指标 WAS版本号 7.0 操作系统 Windows 2008 系统位数 64bit 内存 ...

  4. OpenLayers加载天地图

    openlayer 是基于JavaScript的webGIS库 ,通过openlayer可以很容易的调用地图,并做相应的操作. 在head中载入openlayer的js文件: <link rel ...

  5. js中的DOM节点

    文档对象模型DOM(Document Object Model)定义访问和处理HTML文档的标准方法. DOM 将HTML文档呈现为带有元素.属性和文本的树结构(节点树). 把上面的代码拆分为Dom节 ...

  6. HTML DOM节点的增删改查

    上篇博客中,我们已经初步接触了DOM基础,可是我们学习是为了可以更好地应用,今天我们就来看看DOM节点的增删改查. 无论在哪里,我们想要操作一个东西,总是应该先去获得它.那么我们怎么获得呢? HTML ...

  7. Mac OS X 安装Ruby

    安装CocoaPods第一步 起因:重装系统后需要重新安装CocoaPods网上搜了下发现很多都过时了,已经不能用了.而且taobao Gems源已经停止服务,现在有ruby-china提供服务 PS ...

  8. 多媒体开发之rtp 打包发流---udp 丢包问题

    http://blog.csdn.net/acs713/article/details/19339707

  9. hiho一下 第二周&第四周:从Trie树到Trie图

    hihocoder #1014 题目地址:http://hihocoder.com/problemset/problem/1014 hihocoder #1036 题目地址: http://hihoc ...

  10. liunx 下安装 php_screw 扩展 以及报错处理

    php_screw 是一个 php 源代码加密扩展.首先来看一下 php_screw 在liunx下是如何安装的 首先 去源完整下载 安装包,现在的最新版是 1.5,我们就用1.5 来做个实例 如果有 ...