题目

传送门

思路

暴力!暴力!暴力!

代码

#include<iostream>
#include<cstdio>
using namespace std;
void read(int &x)
{
    x=0;
    int f=1;
    char c=getchar();
    while('0'>c||c>'9')
    {
        if(c=='-')
            f=-1;
        c=getchar();
    }
    while('0'<=c&&c<='9')
    {
        x=(x<<3)+(x<<1)+c-'0';
        c=getchar();
    }
    x*=f;
}
void read(long long &x)
{
    x=0;
    long long f=1;
    char c=getchar();
    while('0'>c||c>'9')
    {
        if(c=='-')
            f=-1;
        c=getchar();
    }
    while('0'<=c&&c<='9')
    {
        x=(x<<3)+(x<<1)+c-'0';
        c=getchar();
    }
    x*=f;
}
void write(int x)
{
    if(x<10)
        putchar(x+'0');
    else
    {
        write(x/10);
        write(x%10);
    }
}
void write(long long x)
{
    if(x<10)
        putchar(x+'0');
    else
    {
        write(x/10);
        write(x%10);
    }
}
int n,m;
int s;
int dx[5]={0,0,0,1,1};
int dy[5]={0,0,1,0,1};
int ans;
bool vis[1005][1005];
char a[1005][1005];
char b[3][3];
int check(int x,int y)
{
    if(1<=x&&x<=n&&1<=y&&y<=m)
    {
        int ret=0;
        for(int i=1;i<=4;i++)
        {
            int tx=x+dx[i];
            int ty=y+dy[i];
            if(b[dx[i]+1][dy[i]+1]==a[tx][ty])
                ret++;
        }
        return ret;
    }
    else
        return 0;
}
bool pd(int x,int y)
{
    if(1<=x&&x<=n&&1<=y&&y<=m)
    {
        for(int i=1;i<=4;i++)
        {
            int tx=x+dx[i];
            int ty=y+dy[i];
            if(vis[tx][ty])
                return 1;
        }
    }

    return 0;
}
int work(int x,int y)
{
    int ret=0;
    if(check(x-1,y-1)==4)
        ret++;
    if(check(x,y-1)==4)
        ret++;
    if(check(x-1,y)==4)
        ret++;
    if(check(x,y)==4)
        ret++;
    return ret;
}
int main()
{
    cin>>n>>m;
    for(int i=1;i<=n;i++)
        for(int j=1;j<=m;j++)
            cin>>a[i][j];
    for(int i=1;i<=2;i++)
        for(int j=1;j<=2;j++)
            cin>>b[i][j];
    for(int i=1;i<n;i++)
    {
        for(int j=1;j<m;j++)
        {
            int al=check(i,j);
            if(al==4)
            {
                for(int k=1;k<=4;k++)
                {
                    int tx=i+dx[k];
                    int ty=j+dy[k];
                    vis[tx][ty]=1;
                }
                s++;
            }

        }
    }
    for(int i=1;i<=n;i++)
    {
        for(int j=1;j<=m;j++)
        {
            char las=a[i][j];
            if(las!='J')
            {
                a[i][j]='J';
                ans=max(ans,s+work(i,j));
            }
            if(las!='O')
            {
                a[i][j]='O';
                ans=max(ans,s+work(i,j));
            }
            if(las!='I')
            {
                a[i][j]='I';
                ans=max(ans,s+work(i,j));
            }
            a[i][j]=las;
        }
    }
    cout<<ans;
    return 0;
}
01-13 07:06