uva 1330 - City Game 模拟

简介:

    扫描线,记录l,r,u,答案就是(r+l-1)*u

    实际上只要开个2维数组就可以了

/*
author:jxy
lang:C/C++
university:China,Xidian University
**If you need to reprint,please indicate the source**
*/
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <algorithm>
using namespace std;
#define Maxn 1005
typedef int ma[Maxn][Maxn];
int w,h;
char org[Maxn][Maxn];
ma l,r,u;
int main()
{
    int T;
    scanf("%d",&T);
    while(T--)
    {
        scanf("%d%d",&h,&w);
        int i,j;
        for(i=1;i<=h;i++)
            for(j=1;j<=w;j++)
            {
                org[i][j]=getchar();
                while(org[i][j]!='F'&&org[i][j]!='R')
                    org[i][j]=getchar();
            }
        int now=0,ans=0;
        for(i=0;i<=w;i++)l[0][i]=r[0][i]=1005;
        for(i=0;i<=w;i++)u[0][i]=0;
        for(i=1;i<=h;i++)
        {
            now=0;
            for(j=1;j<=w;j++)
            {
                if(org[i][j]=='R')
                {
                    l[i][j]=10000;u[i][j]=now=0;
                    continue;
                }
                now++;
                l[i][j]=min(l[i-1][j],now);
                u[i][j]=u[i-1][j]+1;
            }
            now=0;
            for(j=w;j>=1;j--)
            {
                if(org[i][j]=='R')
                {
                    r[i][j]=10005;now=0;
                    continue;
                }
                now++;
                r[i][j]=min(r[i-1][j],now);
                ans=max(ans,(l[i][j]+r[i][j]-1)*u[i][j]);
            }

        }
        printf("%d\n",ans*3);
    }
}



半年以后重写:

/*
author:jxy
lang:C/C++
university:China,Xidian University
**If you need to reprint,please indicate the source**
*/
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <algorithm>
using namespace std;
char org[1005][1005];
int up[1005][1005],Left[1005][1005],Right[1005][1005],space;//space为当前位置行空格
#define INF 100000000
int main()
{
    int T;
    int n,m;
    scanf("%d",&T);
    while(T--){
        scanf("%d%d",&n,&m);
        int i,j;
        for(i=1;i<=n;i++)
          for(j=1;j<=m;j++)
            scanf(" %c",&org[i][j]);
        for(j=0;j<=m;j++)
        {
            up[0][j]=0;
            Left[0][j]=Right[0][j]=INF;
        }
        for(i=1;i<=n;i++)
        {
            space=0;
            for(j=1;j<=m;j++)
            {
                if(org[i][j]=='R')
                {
                    up[i][j]=0;
                    Left[i][j]=Right[i][j]=INF;
                    space=0;
                    continue;
                }
                up[i][j]=up[i-1][j]+1;
                Left[i][j]=min(Left[i-1][j],space++);
            }
        }
        int ans=0;
        for(i=1;i<=n;i++)
            for(j=m,space=0;j>=1;j--)
            {
                if(org[i][j]=='R')
                {
                    space=0;
                    continue;
                }
                Right[i][j]=min(Right[i-1][j],space++); //获得右边边界,不含自己
                ans=max(ans,(Left[i][j]+Right[i][j]+1)*up[i][j]);
            }
        printf("%d\n",ans*3);
    }
}


目录
相关文章
|
算法
uva 10891 game of sum
题目链接 详细请参考刘汝佳《算法竞赛入门经典训练指南》 p67
42 0
|
人工智能 并行计算
|
人工智能 BI
|
机器学习/深度学习
poj 1733 Parity game
点击打开poj 1733 思路: 带权并查集 分析: 1 题目给定n个条件,要我们找到第一个不满足条件的编号 2 每一个条件给的是区间[l,r]的1的奇偶数,很明显[l,r]这个区间的1的个数可以由[0,r]-[0,l-1]得来 3 那...
870 0
uva 1330 City Game
点击打开链接uva 1330 思路:悬线法求解最大子矩阵 分析: 1 详细资料请见点击打开链接 2 有个地方需要注意的是输入格式,有可能输入字母后面会有多个空格,所以必须要过滤掉这些空格 代码: #include #includ...
861 0