zoukankan      html  css  js  c++  java
  • poj 1964 City Game

    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 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 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
      1 #include<cstdio>
      2 #include<iostream>
      3 //#include<cstring>
      4 //include<algorithm>
      5 //#include<cmath>
      6 //#include<vector>
      7 //#include<queue>
      8 //#include<set>
      9 #define INF 0x3f3f3f3f
     10 #define N 1005
     11 #define re register
     12 #define Ii inline int
     13 #define Il inline long long
     14 #define Iv inline void
     15 #define Ib inline bool
     16 #define Id inline double
     17 #define ll long long
     18 #define Fill(a,b) memset(a,b,sizeof(a))
     19 #define R(a,b,c) for(register int a=b;a<=c;++a)
     20 #define nR(a,b,c) for(register int a=b;a>=c;--a)
     21 #define Min(a,b) ((a)<(b)?(a):(b))
     22 #define Max(a,b) ((a)>(b)?(a):(b))
     23 #define Cmin(a,b) ((a)=(a)<(b)?(a):(b))
     24 #define Cmax(a,b) ((a)=(a)>(b)?(a):(b))
     25 #define D_e(x) printf("
    &__ %d __&
    ",x)
     26 #define D_e_Line printf("-----------------
    ")
     27 #define D_e_Matrix for(re int i=1;i<=n;++i){for(re int j=1;j<=m;++j)printf("%d ",g[i][j]);putchar('
    ');}
     28 using namespace std;
     29 //The Code Below Is Bingoyes's Function Forest.
     30 Ii read(){
     31     int s=0,f=1;char c;
     32     for(c=getchar();c>'9'||c<'0';c=getchar())if(c=='-')f=-1;
     33     while(c>='0'&&c<='9')s=s*10+(c^'0'),c=getchar();
     34     return s*f;
     35 }
     36 Iv print(ll x){
     37     if(x<0)putchar('-'),x=-x;
     38     if(x>9)print(x/10);
     39     putchar(x%10^'0');
     40 }
     41 /*
     42 Iv Floyd(){
     43     R(k,1,n)
     44         R(i,1,n)
     45             if(i!=k&&dis[i][k]!=INF)
     46                 R(j,1,n)
     47                     if(j!=k&&j!=i&&dis[k][j]!=INF)
     48                         Cmin(dis[i][j],dis[i][k]+dis[k][j]);
     49 }
     50 Iv Dijkstra(int st){
     51     priority_queue<int>q;
     52     R(i,1,n)dis[i]=INF;
     53     dis[st]=0,q.push((nod){st,0});
     54     while(!q.empty()){
     55         int u=q.top().x,w=q.top().w;q.pop();
     56         if(w!=dis[u])continue;
     57         for(re int i=head[u];i;i=e[i].nxt){
     58             int v=e[i].pre;
     59             if(dis[v]>dis[u]+e[i].w)
     60                 dis[v]=dis[u]+e[i].w,q.push((nod){v,dis[v]});
     61         }
     62     }
     63 }
     64 Iv Count_Sort(int arr[]){
     65     int k=0;
     66     R(i,1,n)
     67         ++tot[arr[i]],Cmax(mx,a[i]);
     68     R(j,0,mx)
     69         while(tot[j])
     70             arr[++k]=j,--tot[j];
     71 }
     72 Iv Merge_Sort(int arr[],int left,int right,int &sum){
     73     if(left>=right)return;
     74     int mid=left+right>>1;
     75     Merge_Sort(arr,left,mid,sum),Merge_Sort(arr,mid+1,right,sum);
     76     int i=left,j=mid+1,k=left;
     77     while(i<=mid&&j<=right)
     78         (arr[i]<=arr[j])?
     79             tmp[k++]=arr[i++]:
     80             (tmp[k++]=arr[j++],sum+=mid-i+1);//Sum Is Used To Count The Reverse Alignment
     81     while(i<=mid)tmp[k++]=arr[i++];
     82     while(j<=right)tmp[k++]=arr[j++];
     83     R(i,left,right)arr[i]=tmp[i];
     84 }
     85 Iv Bucket_Sort(int a[],int left,int right){
     86     int mx=0;
     87     R(i,left,right)
     88         Cmax(mx,a[i]),++tot[a[i]];
     89     ++mx;
     90     while(mx--)
     91         while(tot[mx]--)
     92             a[right--]=mx;
     93 }
     94 */
     95 int a[N][N];ll s[N][N];
     96 Il Maximum_Submatrix(int n,int m){
     97     ll ans=0;
     98     R(i,1,n)
     99         R(j,1,m){
    100             char ch;
    101             cin>>ch;
    102             s[i][j]=s[i-1][j]+s[i][j-1]-s[i-1][j-1]+((ch=='F')?1:-INF);//Matrix prefix sum.
    103         }
    104     R(i,1,n)
    105         R(j,i,n){
    106             ll sum=0;
    107             R(k,1,m)
    108                 Cmin(sum,s[j][k]-s[i-1][k]),Cmax(ans,s[j][k]-s[i-1][k]-sum);
    109         }
    110     return ans;
    111 }
    112 #define Outprint(x) print(x),putchar('
    ');
    113 int main(){
    114     int T=read();
    115     while(T--){
    116         int n=read(),m=read();
    117         ll ans=Maximum_Submatrix(n,m);
    118         ans*=3;//Convert area to money.
    119         Outprint(ans);
    120     }
    121     return 0;
    122 }
    123 /*
    124     Note:
    125         Get the maximum submatrix as the area.
    126     Error:
    127         Rember to add 'return'(especially in 'inline long long').
    128 */
    View Code
  • 相关阅读:
    angular 写 文字省略显示指令
    REACT 学习之一:普通表单过滤
    怎么能够做到实时的邮件监听-- 求指点
    C++实现Behavioral
    private virtual in c++
    接口污染
    C++ 虚函数&纯虚函数&抽象类&接口&虚基类(转)
    c++ override 关键字
    virtual function c++
    删完垃圾代码2
  • 原文地址:https://www.cnblogs.com/bingoyes/p/10184987.html
Copyright © 2011-2022 走看看