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. 多数据源动态关联报表的制作(birt为例)

    使用Jasper或BIRT等报表工具时,常会碰到一些很规的统计,用报表工具本身或SQL都难以处理,比方与主表相关的子表分布在多个数据库中,报表要展现这些数据源动态关联的结果.集算器具有结构化强计算引擎 ...

  2. sql语句偶记录

    查看表结构: show FULL COLUMNS FROM tablename;

  3. logstash5安装并实现mariadb数据写入到elasticsearch

    java环境这里默认安装了 ,一般源码安装,这里就不说了 一.安装logstash 安装logstash可以用yum安装,也可以用源码安装: yum安装: 1.导入GPG: rpm --import ...

  4. 解决PHP显示Warning和Notice等问题

    PHP在安装后,会在php.ini 文件中设置报错.提醒.警告等方式的出现,这样的方式可以使我们在调试PHP程序的时候能及时了解程序所存在的问题.然后,有时候我们并不需要提醒.警告 等内容,比如当我们 ...

  5. MyEclipse配置输出控制台信息至文本文件里

    有时会遇到这种情况.输出的信息过多,console控制台显示不全然.这是就须要将输出的信息输出到文本文件里,既能够查看也能够备份. 1.右击须要执行的项目->Run As->Run Con ...

  6. 浅谈BloomFilter【上】基本概念和实现原理

        在日常生活中.包括在设计计算机软件时,我们常常要推断一个元素是否在一个集合中.     比方在字处理软件中,须要检查一个英语单词是否拼写正确(也就是要推断 它是否在已知的字典中).在 FBI. ...

  7. win7上python+theano+keras安装

    https://blog.csdn.net/yongjiankuang/article/details/50485610 其实过程很简单,首先说一下安装条件: 1.win7 (32和64都可以,下载安 ...

  8. JavaScript的split()

    JavaScript split() 方法 JavaScript String 对象 定义和用法 split() 方法用于把一个字符串分割成字符串数组. 语法 stringObject.split(s ...

  9. jquery将form表单序列化常json

    var formData = {};$.each(form.serializeArray(),function(i, item){ formData[item.name] = item.value;} ...

  10. Java 获取指定日期的方法汇总

    import java.text.DateFormat; import java.text.ParsePosition; import java.text.SimpleDateFormat; impo ...