HDU 之 City Game
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
R reserved unit
F free unit
In the end of each area description there is a separating line.
Output
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的更多相关文章
- HDU 1505 City Game (hdu1506 dp二维加强版)
F - City Game Time Limit:1000MS Memory Limit:32768KB 64bit IO Format:%I64d & %I64u Submi ...
- HDU 3634 City Planning (离散化)
City Planning Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)Tot ...
- hdu 3624 City Planning(暴力,也可扫描线)
City Planning Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others) To ...
- HDU 5013 City Tour
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=5013 题意: 思路: 这里有错,是Hi(x)=sigama(Hji)(j属于x) const int ...
- HDU 1505 City Game(01矩阵 dp)
Problem Description Bob is a strategy game programming specialist. In his new city building game the ...
- HDU 1505 City Game(DP)
City Game Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others) Total ...
- HDU 1505 City Game
这题是上一题的升级版 关键在于条形图的构造,逐行处理输入的矩阵,遇到'F'则在上一次的条形图基础上再加1,遇到'R'则置为0 然后用上一题的算法,求每行对应条形图的最大矩阵的面积. 另外:本来是deb ...
- HDU 1505 Largest Rectangle in a Histogram && HDU 1506 City Game(动态规划)
1506意甲冠军:给你一个连续的直方图(拼贴底部长度1).求连续基质区. 对每一个直方图,分别向左向右进行扩展. #include<cstdio> #include<stdlib.h ...
- HDU - 4496 City 逆向并查集
思路:逆向并查集,逆向加入每一条边即可.在获取联通块数量的时候,直接判断新加入的边是否合并了两个集合,如果合并了说明联通块会减少一个,否则不变. AC代码 #include <cstdio> ...
随机推荐
- J2EE之字符编码输出
1. public void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletExcepti ...
- php单元测试入门教程phpunit详解
本文档提供了一些phpunit官方教程没有提到的信息,帮助初学者快速了解php单元测试,在phpunit官网提供了详细的中文教程,可选多种格式下载 phpunit官网地址:https://phpuni ...
- SpringCloud系列三:将微服务注册到Eureka Server上
1. 回顾 通过上篇博客的讲解,我们知道硬编码提供者地址的方式有不少问题.要想解决这些问题,服务消费者需要一个强大的服务发现机制,服务消费者使用这种机制获取服务提供者的网络信息.不仅如此,即使服务提供 ...
- dotnet 各个版本的下载链接----Download .NET SDKs for Visual Studio
https://dotnet.microsoft.com/download/visual-studio-sdks Not sure what to download? See recommended ...
- 在集群中使用文件加载graph
从hdfs上加载文件并创建graph scala> var graphs = GraphLoader.edgeListFile(sc,"/tmp/dataTest/graphTest. ...
- hbase的数据模型
hbase类似bigTable是一个分布式的数据库,它是一个稀疏的,长期存储的,多维的,排序的映射表,这张表的索引是行关键字,列关键字,时间戳.hbase中的数据都是字符串,没有类型. ...
- web.xml中url-pattern匹配规则
小知识 一般的URL组成 URL = 服务器地址 + RequestURI 例如URI:http://localhost:8080/practice/main [http://localhost:80 ...
- oracle高性能的SQL语句的写法
1.当多表查询的时候,把数据量小的表放在最后面,ORACLE会把最后面的表当作基础表,因为表间连接时,最右边的表会被放到嵌套循环的最外层.最外层的循环次数越少,效率越高. 2.Oracle采用自下而上 ...
- ubuntu中文乱码--添加中文字符集
在Ubuntu支持中文后(方法见上篇文章),默认是UTF-8编码,而Windows中文版默认是GBK编码.为了一致性,通常要把Ubuntu的默认 编码改为GBK.当然你也可以不改,但这会导致我们在两个 ...
- k8s部署dns
硬件环境: 两台虚拟机, 10.10.20.203 部署docker.etcd.flannel.kube-apiserver.kube-controller-manager.kube-schedule ...