十月例题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 ...
随机推荐
- mysql 导出,导入数据
导出 加-d代表只导出表结构 命令行下具体用法如下: mysqldump -u用户名 -p密码 -d 數據库名 表名 脚本名; 1.导出数据库为dbname的表结构(其中用户名为root, ...
- ERROR 2003 (HY000): Can't connect to MySQL server on 'ip'(111)
问题描述: 从一台linux远程连接另一台linux上的MySQL, 出现ERROR 2003 (HY000): Can't connect to MySQL server on 'ip'(111) ...
- 各种Markdown处理器的列表
从MarkdownImplementations - Markdown Community Group可以找到一个实现markdown处理器的列表,如下: Name Language Type Des ...
- HDOJ 4696 Answers 乱搞
乱搞: rt.有1就能输出全部的数,否则仅仅能输出偶数 Answers Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 131072/1 ...
- Git 经常使用的命令
查看.参加.服从.删.恢复,复位更改文件 git help <command> # 演出command的help git show # 显示的提交内容 git show $id git c ...
- Qt 学习之路 :使用 QJson 处理 JSON
XML 曾经是各种应用的配置和传输的首选方式.但是现在 XML 遇到了一个强劲的对手:JSON.我们可以在 这里 看到有关 JSON 的语法.总体来说,JSON 的数据比 XML 更紧凑,在传输效率上 ...
- Qt 学习之路:线程总结
前面我们已经详细介绍过有关线程的一些值得注意的事项.现在我们开始对线程做一些总结. 有关线程,你可以做的是: 在QThread子类添加信号.这是绝对安全的,并且也是正确的(前面我们已经详细介绍过,发送 ...
- URAL 1988 - Planet Ocean Landing【几何&三分答案】
[题意] 在一个星球(是一个球体)表面有一个飞机(坐标(x1,y1,z1),原点是星球中心),在空中有一个空间站(坐标(x2,y2,z2)),所有值均小于100,现在要使飞机与空间站相遇,飞机的速度是 ...
- Css实现透明效果,兼容IE8
Css实现透明效果,兼容IE8 >>>>>>>>>>>>>>>>>>>>> ...
- 共享受限资源,Brian的同步规则
说明:如果一个变量是boolean,则此变量是原子性的,即赋值和返回值简单的操作在发生时没有中断的可能. 递增不是原子性炒作. 解决共享资源竞争: 1. 通过加锁,锁语句会产生相互排斥的效果,此种机制 ...