跳到正文

个人记录

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

tanghaocheng约 2 分钟
原文
文章信息与版本

文章信息

收录
2026年5月30日
更新
2026年6月27日
篇幅
约 2 分钟

版本

  1. v1当前

简单的模拟题。

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

注意:

  • 当有 ti,j,1t_{i,j,1} 为 L 时要注意每一个格子不要获得超过 11 次。
  • 由于 ti,j,2t_{i,j,2} 的最大值可以达到 10910^9,所以要使用 long long\text{long long}。
C++
#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;
}
原文