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的结果

大致思路,扫描法,扫描他的运动极限。

  1. #include<stdio.h>
  2. #include<string.h>
  3. int main()
  4. {
  5. char s[];
  6. int l[],r[],d[][];
  7. int i,j,n,m,t,max,res;
  8. scanf("%d",&t);
  9. while(t--)
  10. {
  11. memset(d,,sizeof(d));
  12. scanf("%d%d",&n,&m);
  13. res=;
  14. for(i=;i<=n;i++)
  15. {
  16. for(j=;j<=m;j++)
  17. {
  18. scanf("%s",s);
  19. if(s[]=='F')
  20. d[i%][j]=d[(i-)%][j]+; //滚动数组
  21. else
  22. d[i%][j]=;
  23. l[j]=r[j]=j;
  24. }
  25. for(j=;j<=m;j++)
  26. {
  27. while(l[j]>&&d[i%][l[j]-]>=d[i%][j])
  28. l[j]=l[l[j]-];
  29. } //向左延伸
  30. for(j=m-;j>=;j--)
  31. {
  32. while(r[j]<m&&d[i%][r[j]+]>=d[i%][j])
  33. r[j]=r[r[j]+];
  34. } //向右延伸
  35. max=;
  36. for(j=;j<=m;j++)
  37. if((r[j]-l[j]+)*d[i%][j]>max)
  38. max=(r[j]-l[j]+)*d[i%][j];
  39. if(max>res)
  40. res=max;
  41. }
  42. printf("%d\n",res*);
  43. }
  44. return ;
  45. }

十月例题F题 - City Game的更多相关文章

  1. 2013年山东省赛F题 Mountain Subsequences

    2013年山东省赛F题 Mountain Subsequences先说n^2做法,从第1个,(假设当前是第i个)到第i-1个位置上哪些比第i位的小,那也就意味着a[i]可以接在它后面,f1[i]表示从 ...

  2. 2017Summmer_上海金马五校 F题,G题,I题,K题,J题

    以下题目均自己搜 F题  A序列 一开始真的没懂题目什么意思,还以为是要连续的子串,结果发现时序列,简直智障,知道题意之后,好久没搞LIS,有点忘了,复习一波以后,直接双向LIS,处理处两个数组L和R ...

  3. ACM-ICPC 2019南昌网络赛F题 Megumi With String

    ACM-ICPC 南昌网络赛F题 Megumi With String 题目描述 给一个长度为\(l\)的字符串\(S\),和关于\(x\)的\(k\)次多项式\(G[x]\).当一个字符串\(str ...

  4. 2019牛客多校第八场 F题 Flowers 计算几何+线段树

    2019牛客多校第八场 F题 Flowers 先枚举出三角形内部的点D. 下面所说的旋转没有指明逆时针还是顺时针则是指逆时针旋转. 固定内部点的答案的获取 anti(A)anti(A)anti(A)或 ...

  5. AtCoder Beginner Contest 215 F题题解

    F - Dist Max 2 什么时候我才能突破\(F\)题的大关... 算了,不说了,看题. 简化题意:给定\(n\)个点的坐标,定义没两个点的距离为\(min(|x_i-x_j|,|y_i-y_j ...

  6. NEFU 2016省赛演练一 F题 (高精度加法)

    Function1 Problem:F Time Limit:1000ms Memory Limit:65535K Description You know that huicpc0838 has b ...

  7. hdu5514Frogs(2015ACM-ICPC沈阳赛区F题)

    这题很容易转化到一个容斥计数问题.而用指数复杂度的枚举计数法显然会挂,只能考虑别的方法. 首先将a[i]用gcd(a[i], m)替换,排序去重后得到一组m的约数,而m不超过1e9,因此m的所有约数最 ...

  8. 周赛F题 POJ 1458(最长公共子序列)

    F - F Time Limit:1000MS     Memory Limit:10000KB     64bit IO Format:%I64d & %I64u   Description ...

  9. (中等) Hiho 1232 Couple Trees(15年北京网络赛F题),主席树+树链剖分。

    "Couple Trees" are two trees, a husband tree and a wife tree. They are named because they ...

随机推荐

  1. Java做界面的感想。。

    我用Swing做出的例子: JavaFX做出的界面: 后来又做出了自己编写的一套基于Synth的L&F,其与直接在代码中重绘某个组件不同,最大优点是具有可插拔性,即在不改变原有程序代码的情况下 ...

  2. matches()方法

    java.lang包中的String类和java.util.regex包中的Pattern,Matcher类中都有matches()方法,都与正则表达式有关.下面我分别举例:(字符串:"ab ...

  3. Delphi TFindDialog TReplaceDialog对话框在Memo中的使用

    Delphi TFindDialog TReplaceDialog对话框的使用 下载地址1: http://download.csdn.net/detail/teststudio/6408383   ...

  4. Lucene.Net+盘古分词

    前言 各位朋友,谢谢大家的支持,由于文件过大,有考虑到版权的问题,故没有提供下载,本人已建立一个搜索技术交流群:77570783,源代码已上传至群共享,需要的朋友,请自行下载! 首先自问自答几个问题, ...

  5. MYSQL查询计划KEY_LEN

    http://www.innomysql.com/article/25241.html 1 key_len的含义 2 MySQL中key_len计算规则 3 通过key_len分析联合索引 本文首先介 ...

  6. [转] 在React Native中使用ART

    http://bbs.reactnative.cn/topic/306/%E5%9C%A8react-native%E4%B8%AD%E4%BD%BF%E7%94%A8art 前半个月捣腾了一下Rea ...

  7. Markdown写接口文档,自动添加TOC

    上回说到,用Impress.js代替PPT来做项目展示.这回换Markdown来做接口文档好了.(不敢说代替Word,只能说个人感觉更为方便)当然,还要辅之以Git,来方便版本管理. Markdown ...

  8. colspan是跨列,rowspan是跨行

    colspan是跨列,rowspan是跨行,可以看作是网页设计表格中的列和行的一个属性.跨列相当于把两列或者多列合并成一个单元格:跨行同理是把两行或者多行合并成一行:colspan和rowspan分别 ...

  9. HTML5+移动APP(2)

    原理: html 页面负责内容: ui 负责页面样式: js 负责调用原生app方法. html5: html5这部分负责页面,也就是app中你看到的东西,大概的架构和内容 ui: mui 介绍:和H ...

  10. WCF,WebAPI,WCFREST和WebService的区别

    Web ServiceIt is based on SOAP and return data in XML form.It support only HTTP protocol.It is not o ...