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> ...
随机推荐
- 无需Root实现Android手机屏幕流畅投影到电脑进行演示(附软件下载)
近期要在公司的会议上演示App,须要在投影仪上显示出来给大家演示.因为投影仪不是智能投影仪,仅仅能将App先投影到自己的笔记本上.然后再将笔记本上的内容投影到投影仪上.该App是个游戏,实时交互性比較 ...
- Mac下面的SecureCRT(附破解方案) 更新到最新的7.3.2(转)
转自 http://bbs.weiphone.com/read-htm-tid-6939481.html 继续更新到7.3.2的破解.只是升级了下secureCRT到7.3.2,方法还是不变 相信很多 ...
- 解决ubuntukylin 13.10安装wine时无法解决软件包依赖问题
在ubuntukylin 13.10中,无论是在软件中心安装wine还是通过apt-get install安装wine都会出现软件包依赖问题且无法解决. 问题重现 在软件中心安装wine报错例如以下: ...
- Eureka 源码编译安装部署---Eureka运行eureka-server服务
---恢复内容开始--- 折腾了几天,终于运行好了,两个字:佩服 首先感谢这个大佬的博客支持:https://www.cnblogs.com/lifuping/p/5663127.html 1.首先在 ...
- CSS基础2——选择器
前面说过样式规则.也知道了样式规则语法形式为:选择器+声明块 如:div{ color:black:padding:10px; } div即表示选择器(此处是元素选择器),花括号里的内容就是声明块 ...
- 标准库 - 输入输出处理(input and output facilities) lua
标准库 - 输入输出处理(input and output facilities)责任编辑:cynthia作者:来自ITPUB论坛 2008-02-18 文本Tag: Lua [IT168 技术文档] ...
- Android内容提供者
一个应用中的数据库对别人是不会提供直接的访问的,而是提供接口给别人访问,但是一般应用开发的时候都是去获取别人的数据,而不是自己提供数据. 继承ContentProvider: 在Menifest中注册 ...
- golang struct 定义中json``解析说明
在代码学习过程中,发现struct定义中可以包含`json:"name"`的声明,所以在网上找了一些资料研究了一下 package main import ( "enco ...
- PowerBuilder--Aes128加解密
通过C#开发Com控件,注册到系统,然后由pb通过OLEObject进行调用 原文:https://www.cnblogs.com/eric_ibm/archive/2012/07/06/dll.ht ...
- PHP插入法排序
/** 插入排序(Insertion Sort)的算法描述是一种简单直观的排序算法. 它的工作原理是通过构建有序序列,对于未排序数据,在已排序序列中从后向前扫描, 找到相应位置并插入.插入排序在实现上 ...