十月例题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 ...
随机推荐
- Linux 下DNS服务器主从配置
注意: 关闭防火墙 关闭selinux 在客户端配置vim /etc/resolv.conf的DNS 安装 yum install -y bind bind-chroot bind-utils ...
- nrf51822蓝牙芯片ble_app_proximity程序总结
近期由于钥匙的事情,研究了下官方自带的ble_app_proximity程序,事实上就是跟防丢有关系的程序. 同一时候也发现了看nordic程序的一些门道,主要还是看协议栈里面的一些service,首 ...
- WCF - 绑定后续之自定义绑定
自定义信道基类 WCF是一个极具扩展性的通信框架 无论在服务模型层还是信道层 都具有很多扩展点 而信道层的扩展点主要体现在实现自定义信道以增强信道栈处理信息的能力 比如我们可以扩展信道层 实现一个自定 ...
- linux device driver —— 环形缓冲区的实现
还是没有接触到怎么控制硬件,但是在书里看到了一个挺巧妙的环形缓冲区实现. 此环形缓冲区实际为一个大小为bufsize的一维数组,有一个rp的读指针,一个wp的写指针. 在数据满时写进程会等待读进程读取 ...
- Android开发:最详细的 Toolbar 开发实践总结
最详细的 Toolbar 开发实践总结 过年前发了一篇介绍 Translucent System Bar 特性的文章 Translucent System Bar 的最佳实践,收到很多开发者的关注和反 ...
- ArrayBlockingQueue 源码阅读 问题(一)
今天阅读java.util.concurrent 中 ArrayBlockingQueue 的源码,发现其中有很多下面这行代码 final ReentrantLock lock = this.lock ...
- 好用的log
Log.getStackTraceString(new Throwable())
- bootstrap01登录小例子
引入需要的bootstrap文件 <!DOCTYPE html> <html> <head lang="en"> <meta charse ...
- C# 内存管理优化畅想----前言
C#语法简洁.优雅,类库丰富,是我最喜爱的计算机语言,没有“之一”.但是,经过深入学习后发现,C#的内存管理,也就是通常所说的垃圾回收(GC)机制,虽然跟其他支持GC的语言相比,已经很优秀了,但与手动 ...
- ratingBar抢焦点问题
ratingBar抢viewpager焦点问题: 1)写一个类继承ratingBar,让onTouchevent或者dispatchTouchEvent返回false 2)设置ratingBar的属性 ...