十月例题F题 - City Game
Time Limit:3000MS Memory Limit:0KB 64bit IO Format:%lld & %llu
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
题解:给定一个m*n的矩阵,其中一些格子是空地(F),其他障碍是(R),找到一个全部由F组成的面积最大的子矩阵,输出其面积乘3的结果
大致思路,扫描法,扫描他的运动极限。
#include<stdio.h>
#include<string.h>
int main()
{
char s[];
int l[],r[],d[][];
int i,j,n,m,t,max,res;
scanf("%d",&t);
while(t--)
{
memset(d,,sizeof(d));
scanf("%d%d",&n,&m);
res=;
for(i=;i<=n;i++)
{
for(j=;j<=m;j++)
{
scanf("%s",s);
if(s[]=='F')
d[i%][j]=d[(i-)%][j]+; //滚动数组
else
d[i%][j]=;
l[j]=r[j]=j;
}
for(j=;j<=m;j++)
{
while(l[j]>&&d[i%][l[j]-]>=d[i%][j])
l[j]=l[l[j]-];
} //向左延伸
for(j=m-;j>=;j--)
{
while(r[j]<m&&d[i%][r[j]+]>=d[i%][j])
r[j]=r[r[j]+];
} //向右延伸
max=;
for(j=;j<=m;j++)
if((r[j]-l[j]+)*d[i%][j]>max)
max=(r[j]-l[j]+)*d[i%][j];
if(max>res)
res=max;
}
printf("%d\n",res*);
}
return ;
}
十月例题F题 - City Game的更多相关文章
- 2013年山东省赛F题 Mountain Subsequences
2013年山东省赛F题 Mountain Subsequences先说n^2做法,从第1个,(假设当前是第i个)到第i-1个位置上哪些比第i位的小,那也就意味着a[i]可以接在它后面,f1[i]表示从 ...
- 2017Summmer_上海金马五校 F题,G题,I题,K题,J题
以下题目均自己搜 F题 A序列 一开始真的没懂题目什么意思,还以为是要连续的子串,结果发现时序列,简直智障,知道题意之后,好久没搞LIS,有点忘了,复习一波以后,直接双向LIS,处理处两个数组L和R ...
- ACM-ICPC 2019南昌网络赛F题 Megumi With String
ACM-ICPC 南昌网络赛F题 Megumi With String 题目描述 给一个长度为\(l\)的字符串\(S\),和关于\(x\)的\(k\)次多项式\(G[x]\).当一个字符串\(str ...
- 2019牛客多校第八场 F题 Flowers 计算几何+线段树
2019牛客多校第八场 F题 Flowers 先枚举出三角形内部的点D. 下面所说的旋转没有指明逆时针还是顺时针则是指逆时针旋转. 固定内部点的答案的获取 anti(A)anti(A)anti(A)或 ...
- AtCoder Beginner Contest 215 F题题解
F - Dist Max 2 什么时候我才能突破\(F\)题的大关... 算了,不说了,看题. 简化题意:给定\(n\)个点的坐标,定义没两个点的距离为\(min(|x_i-x_j|,|y_i-y_j ...
- NEFU 2016省赛演练一 F题 (高精度加法)
Function1 Problem:F Time Limit:1000ms Memory Limit:65535K Description You know that huicpc0838 has b ...
- hdu5514Frogs(2015ACM-ICPC沈阳赛区F题)
这题很容易转化到一个容斥计数问题.而用指数复杂度的枚举计数法显然会挂,只能考虑别的方法. 首先将a[i]用gcd(a[i], m)替换,排序去重后得到一组m的约数,而m不超过1e9,因此m的所有约数最 ...
- 周赛F题 POJ 1458(最长公共子序列)
F - F Time Limit:1000MS Memory Limit:10000KB 64bit IO Format:%I64d & %I64u Description ...
- (中等) Hiho 1232 Couple Trees(15年北京网络赛F题),主席树+树链剖分。
"Couple Trees" are two trees, a husband tree and a wife tree. They are named because they ...
随机推荐
- valuestack(值栈) 和 actioncontext(上下文)
Strut2的Action类通过属性可以获得所有相关的值,如请求参数属性值等.要获得这些参数值,我们要做的唯一一件事就是在Action类中声明与参数同名的属性.在Struts2调用Action类的Ac ...
- (C#)与Windows用户账户信息的获取
Console.WriteLine(Environment.UserName); //计算机NetBIOS名称 Console.WriteLine(Environment.MachineName); ...
- 构建ASP.NET MVC4+EF5+EasyUI+Unity2.x注入的后台管理系统(47)-工作流设计-补充
原文:构建ASP.NET MVC4+EF5+EasyUI+Unity2.x注入的后台管理系统(47)-工作流设计-补充 系列目录 补充一下,有人要表单的代码,这个用代码生成器生成表Flow_Form表 ...
- 数据存储(一)--SharedPreferences之你不知道的事
一.SharedPreferences将数据文件保存在指定路径上 SharedPreferences原则上是仅仅能保存在当前应用程序私有的shared_prefs文件夹中,只是也不是绝对的,我们能够用 ...
- tcp-backlog配置
redis tcp-backlog配置 在redis2.8版本中有一个tcp-backlog配置, 说明如下: # TCP listen() backlog.## In high requests ...
- Linux下使用w命令和uptime命令查看系统负载
在Linux系统中查询系统CPU和内存的负载(使用率)时,我们通常习惯于使用top.atop或者ps,这篇文章将要给大家介绍如何使用w命令和uptime命令来查看系统的负载情况,对于uptime命令, ...
- iOS-#ifdef DEBUG代码块介绍
iOS-#ifdef DEBUG宏定义介绍 一.#ifdef DEBUG代码块 #ifdef DEBUG // Debug 模式的代码... #else // Release 模式的代码... #en ...
- Jquery 判断滚动条到达顶部或底部
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/ ...
- sql根据'/'截取最后的字符串
filpath字段值:/DataFile/UpLoad/Logo/NoPhoto.jpg select filpath,REVERSE((SUBSTRING(REVERSE(FilPath),0,CH ...
- 把Excel数据导入到数据库
引入命名空间 using System.IO; using System.Data; using System.Data.OleDb; 引入命名空间 首先要把Excel上传到服务器 //上传Excel ...