HDU 1505 City Game
来源:互联网 发布:在淘宝推销阿里的产品 编辑:程序博客网 时间:2024/05/08 14:16
City Game
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)Total Submission(s): 4603 Accepted Submission(s): 1956
Problem Description
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.
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 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.
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 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
25 6R F F F F FF F F F F FR R R F F FF F F F F FF F F F F F5 5R R R R RR R R R RR R R R RR R R R RR R R R R
Sample Output
450一维的做法 ,需每输入一行 就要判断一次#include <iostream>#include <stdio.h>#include <string.h>#include <stdlib.h>using namespace std;int gao[1011];int ll[1011],rr[1011];int n,m;int maxarea(){ int max=0; int i,j; gao[0]=0; gao[m+1]=0; for(i=1; i<=m; i++) { if(gao[i]==0) continue; j=i-1; if(gao[j] < gao[i]) { ll[i]=j; continue; } else { j=ll[j]; if(gao[j] < gao[i]) { ll[i]=j; continue; } } } for(i=m; i>=1; i--) { if(gao[i]==0) continue; j=i+1; if(gao[j] < gao[i]) { rr[i]=j; continue; } else { j=rr[j]; if(gao[j] < gao[i]) { rr[i]=j; continue; } } } for(i=1; i<=m; i++) { if(gao[i]!=gao[i-1]) { if(max<(rr[i]-ll[i]-1)*gao[i]) max=(rr[i]-ll[i]-1)*gao[i]; } } return max;}int main(){ int T,i,j; char c; scanf("%d",&T); while(T--) { memset(gao,0,sizeof(gao)); //记录最大的长 memset(ll,0,sizeof(ll)); memset(rr,0,sizeof(rr)); //rr-ll+1 即为宽 int max=0; scanf("%d%d",&n,&m); //getchar(); for(i=1; i<=n; i++) { //gets(c); //int len=strlen(c); //int r=1; for(j=1; j<=m; j++) { cin>>c; if(c=='F') gao[j]++; if(c=='R') gao[j]=0; //r++; } int t=maxarea(); if(max<t) max=t; } printf("%d\n",max*3); } return 0;}二维全部输入后 在进行判断#include <cstdio>#include <algorithm>#define LL long longusing namespace std;const int maxn = 1001;int mat[maxn][maxn], up[maxn][maxn], le[maxn][maxn], rig[maxn][maxn];int main(){ int t, ans; int m, n, i, j, lo, ro; scanf("%d",&t); while(t--) { ans = 0; scanf("%d%d", &m, &n); for(i = 0; i < m; i++) { for(j = 0; j < n; j++) { char ch = getchar(); while(ch!='F'&&ch!='R') { ch = getchar(); } mat[i][j] = ch == 'F' ?0:1; } } for(i = 0; i < m; i++) { lo = -1; ro = n; for(j = 0; j < n; j++) { if(mat[i][j] == 1) { //le数组存储的是矩形的左边界 up[i][j] = le[i][j] = 0;//up数组存储的是上边界,相当于长方形的宽 lo = j; } else { up[i][j] = i == 0?1:up[i-1][j] + 1; le[i][j] = i == 0 ? lo+1 : max(le[i-1][j], lo+1); } } for(j = n-1; j >= 0; j--) { if(mat[i][j] == 1) {//rig存储的是矩形的右边界 rig[i][j] = n; ro = j; } else { //rig[i][j] - le[i][j]得到的是矩形的长 rig[i][j] = i ==0 ? ro-1 : min(rig[i-1][j], ro-1); ans = max(ans, up[i][j]*(rig[i][j]-le[i][j]+1)); //他们的乘积是子矩形的面积 } } } printf("%d\n", ans*3); } return 0;}
0 0
- HDU 1505 City Game
- hdu 1505 City Game
- hdu 1505 city game
- HDU 1505 City Game
- hdu 1505 City Game
- hdu 1505 City Game
- HDU 1505 City Game
- HDU 1505 City Game
- hdu 1505 City Game
- HDU - 1505 City Game
- HDU-1505-City Game
- HDU 1505 City Game
- HDU 1505 City Game
- HDU 1505 City Game
- HDU 1505 City Game
- HDU 1505 City Game
- HDU 1505 City Game
- hdu 1505 City Game
- Wrong Answer,Memory Limit Exceeded
- 是否支持该属性的cssAPI
- MYSQL用法(六) 存储过程的创建
- 项目网盘-HDFS任务
- 打车市场“零补贴” 司机不抢单乘客抱怨
- HDU 1505 City Game
- Excel中表单控件和ACTIVEX控件主要区别
- 安装版的tomcat7 "Java heap space"内存溢出解决办法
- Android获取全部联系人信息的例子
- css学习笔记——绘制属于你的缤纷世界
- DOCTYPE的作用
- MySQ 存储引擎选择
- WinCE EBOOT中的Optional函数
- python程序的后台化