HDU 之 City Game

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,布布扣,bubuko.com

时间: 2024-10-02 06:23:04

HDU 之 City Game的相关文章

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

1506题意:给你连续的直方图(底边边长为1),求连续的矩阵面积. 对每个直方图,分别向左向右进行扩展. #include<cstdio> #include<stdlib.h> #include<string.h> #include<string> #include<map> #include<cmath> #include<iostream> #include <queue> #include <sta

HDU 3274 City Planning

题意:给你一组数n  m  n的意思是有多少个村庄,并且给你n-1个关系,m的意思是要你连通的村庄.现在要你求出连通m个村庄所花费的钱 思路:题目一看数据,就像是要你去求最小生成树的子数,但是仔细审题会发现一句"Meanwhile you should use the least money. You may suppose that the initial transportation network makes up a tree."好吧,原来给你的网络图是一棵树,这样题目就直接简

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

F - City Game Time Limit:1000MS     Memory Limit:32768KB     64bit IO Format:%I64d & %I64u Submit Status Practice HDU 1505 Appoint description: Description Bob is a strategy game programming specialist. In his new city building game the gaming enviro

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

City Planning Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others) Total Submission(s): 503    Accepted Submission(s): 213 Problem Description After many years, the buildings in HDU has become very old. It need to rebui

HDU 3634 City Planning (离散化)

题意  给你n个矩形  每个矩形都有自己的value  你可以任意改变矩形的表里关系   被覆盖的地方的value取最表层的   求总value的最大值 刚看了扫描线  感觉这个可以用扫描线做就直接写了  其实直接离散化就行了  因为最多也就20个矩形  那坐标最多也就40个  那我们对坐标进行离散化  然后将矩形按value从小到大一个个的放  暴力更新覆盖格子的value  最后直接将2n * 2n个小格子的value加起来就行了 #include <cstdio> #include &l

hdu 1505 City Game 最大矩形面积 单调队列

City Game Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others) Total Submission(s): 5106    Accepted Submission(s): 2197 Problem Description Bob is a strategy game programming specialist. In his new city building game t

HDU 5013 City Tour

题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=5013 题意: 思路: 这里有错,是Hi(x)=sigama(Hji)(j属于x) const int N=18; int m,n; double p[N],H[N][N]; double f[N][1<<N]; double dp[N][1<<N]; double a[1<<N],aa[1<<N]; double pp[1<<N],qq[1<&

HDU 1505 City Game(01矩阵 dp)

Problem 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 i

hdu 1505 City Game (动态规划)

City Game Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others) Total Submission(s): 4838    Accepted Submission(s): 2071 Problem Description Bob is a strategy game programming specialist. In his new city building game t