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);
    }
}


目录
相关文章
|
6月前
|
算法
uva 10891 game of sum
题目链接 详细请参考刘汝佳《算法竞赛入门经典训练指南》 p67
14 0
LeetCode contest 200 5476. 找出数组游戏的赢家 Find the Winner of an Array Game
LeetCode contest 200 5476. 找出数组游戏的赢家 Find the Winner of an Array Game
|
机器人 定位技术
HDU-1035,Robot Motion(DFS+模拟)
HDU-1035,Robot Motion(DFS+模拟)
|
人工智能 并行计算
|
C++
LeetCode 289 Game of Life(生命游戏)(Array)
版权声明:转载请联系本人,感谢配合!本站地址:http://blog.csdn.net/nomasp https://blog.csdn.net/NoMasp/article/details/52122735 翻译 根据维基百科的文章介绍:“Game of Life,简称为Life,是一个被英国数学家John Conway在1970年提出的细胞自动分裂器。
1608 0
|
人工智能 前端开发 rax
【OJ】1.6.7将军(Check the Check)UVa 10196 // PC 1101017 // acmclub.com 25177
/* 1.6.7将军(Check the Check)UVa 10196 // PC 1101017 // hzu.acmclub.com 25177 */ #include #include using namespace std; char a[10][10]...
1125 0
|
机器学习/深度学习
模拟 --- hdu 12878 : Fun With Fractions
Fun With Fractions Time Limit: 1000ms, Special Time Limit:2500ms, Memory Limit:65536KB Total submit users: 152, Accepted users: 32 ...
829 0
|
机器学习/深度学习
|
测试技术
优先队列+模拟-Fox and Number Game
codeforces-Fox and Number Game 题目地址:http://codeforces.com/contest/389/problem/ATime Limit: 1000msFox Ciel is playing a game with numbers now. Ciel has n positive integers: x1, x2, ..., xn. She
1147 0