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. OpenGL三角形的双面不同颜色的绘制

    对于一个三角形,我要给它正反面不同的颜色.然后通过旋转,看出它的效果. 我只想到了2种方法,下面我来写一下这两种方法. 第一种方法,通过角度的判断重设glColor3f的参数(这种方法局限性很大,不推 ...

  2. android端StarIO热敏打印机打印小票

    最近在做这个热敏打印机打印小票,开始的时候在网上找资料,发现国内基本没有这方面的资料,国外也很少,在此做个打印小票的记录. 这里只记录一些关键点. 使用StarIOPort.searchPrinter ...

  3. nginx实现某个页面http访问,其余全部跳转到https

    全站https实现某个页面可以http访问,其余全部跳转到https,注意下面的location,如果不加root 配置 找不到这个文件的server { listen ; server_name w ...

  4. Memcached的LRU和缓存命中率

    缓存命中率 命中:直接从缓存中读取到想要的数据. 未中:缓存中没有想要的数据,还需要到数据库进行一次查询才能读取到想要的数据. 命中率越高,数据库查询的次数就越少. 读取缓存的速度远比数据库查询的速度 ...

  5. bean对应mapper.xml字段

    在bean中set的时候最好写上这个,避免报空指针............... public void setImgAddress(String imgAddress) { this.imgAddr ...

  6. 【JavaEE】Springmvc+Spring整合及example

    这一篇在前一篇Springmvc的基础上,加上Spring.Spring的主要用途叫做控制反转(依赖注入,IoC/DI)和面向切面的编程(AOP),本文只介绍IoC,因为AOP主要的应用场景是记录日志 ...

  7. web安全之SQL注入---第四章 如何进行SQL注入攻击

    第四章 如何进行SQL注入攻击1.数字注入2.字符串注入    '#    '--

  8. TP的分页加查询

    1.查询显示数据库的内容 控制器里的内容 public function shouye() { $n = M("car"); $arr = $n->select(); $th ...

  9. Entity Framework 4.1:复杂类型

    这篇文章将讨论复杂类型. 默认情况下,EF4.1 将类映射到表,这是约定,但是有时候,我们需要模型比表的粒度更细一些. 地址是一个典型的例子,看一下下面的客户类. )] publicstring St ...

  10. python(pytest)+allure+jenkins 实现接口自动化的思路

    效果图镇楼: 上述各模块作用: python(pytest): 1:用于读测试用例(本次用例写在csv文件中) 2:环境配置相关 3:提取1中的测试数据,组成请求体 4:发送请求 5:获取结果 6:断 ...