F-city Game

Source: Internet
Author: User

FCity Game

Time Limit: 3000MS Memory Limit:0KB 64bit IO Format:%lld &%llu /c3>

Bob is a strategy game programming specialist. In your new city building game the gaming environment
is as Follows:a city was built up by areas, in which there was streets, trees, factories and buildings. There
is still some space in the area of is unoccupied. The strategic task of his game was to win as much
Rent money from these free spaces. To the win rent money must erect buildings, which can only be
Rectangular, as long and wide as you can. Bob is trying to find a from to build the biggest possible
Building in each area. But he comes across some problems-he isn't allowed to destroy already
Existing buildings, trees, factories and streets in the area he's building in.
Each of the area have its width and length. The area was 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 was divided into K areas. Each one of
The areas is rectangular and have a different grid size with its own length M and width N. The existing
Occupied units is marked with the symbol ' R '. The unoccupied units is 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
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 is:
r-reserved Unit
F-free Unit
The end of each area description there are a separating line.
Output
For each data set in the input file print on a separate line with the standard output, the integer
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

The main problems: given a m*n matrix, some of which are empty spaces (F), other obstacles are (R), find a whole area composed of F the largest sub-matrix, the output of its area by 3 results

The general idea, scanning method, scans his motion limits.

#include <stdio.h>#include<string.h>intMain () {Chars[2]; intl[1001],r[1001],d[2][1001]; intI,j,n,m,t,max,res; scanf ("%d",&t);  while(t--) {memset (d,0,sizeof(d)); scanf ("%d%d",&n,&m); Res=0;  for(i=1; i<=n;i++)        {             for(j=1; j<=m;j++) {scanf ("%s", s); if(s[0]=='F') D[i%2][j]=d[(I-1)%2][j]+1;//Scrolling Array                ElseD[i%2][j]=0; L[J]=r[j]=J; }             for(j=2; j<=m;j++)            {                 while(l[j]>1&&d[i%2][l[j]-1]>=d[i%2][j]) l[j]=l[l[j]-1]; }  //Extend left             for(j=m-1; j>=1; j--)            {                 while(r[j]<m&&d[i%2][r[j]+1]>=d[i%2][j]) r[j]=r[r[j]+1]; }  //Extend Rightmax=0;  for(j=1; j<=m;j++)                if((r[j]-l[j]+1) *d[i%2][j]>max) Max= (r[j]-l[j]+1) *d[i%2][j]; if(max>Res) Res=Max; } printf ("%d\n", res*3); }    return 0;}

F-city Game

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.