[Algo Beat Contest 004 B] Buying Lotteries 官方题解

· · 个人记录

简单的模拟题。

只需要记录 t_{i,j,1} 是否存在 L 字符的同时,依次判断 t_{i,j,1} 是否等于 X,依次加上答案即可。

注意:

#include<bits/stdc++.h>
#define int long long
#define ll unsigned long long
#define off ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0)
using namespace std;
const int N=2005;
string x,a[N][N];
int n,m,b[N][N];
signed main()
{
    off; 
    cin>>n>>m;
    cin>>x;
    for(int i=1;i<=n;i++)
    {
        for(int j=1;j<=m;j++)
        {
            cin>>a[i][j];
        }
    }
    bool All=0;
    int ans=0,sum=0;
    for(int i=1;i<=n;i++)
    {
        for(int j=1;j<=m;j++)
        {
            cin>>b[i][j];
            if(a[i][j]=="L")
            {
                All=1;
            }
            else if(a[i][j]==x)
            {
                ans+=b[i][j];
            }
            sum+=b[i][j];
        }
    }
    if(All)
    {
        cout<<sum;
    }
    else
    {
        cout<<ans;
    }
    return 0;
}