Codeforces 984B

本文介绍了一种用于验证扫雷游戏地图有效性的算法实现。通过使用数组记录地图上每个位置周围雷的数量,并与游戏显示的数字进行对比,确保游戏状态的一致性和准确性。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

题目链接

https://vjudge.net/problem/CodeForces-984B

题意

扫雷,给你一片地图,问你是否是有效的,即数字显示得是否正确。

思路

用一个数组记录正确的周围雷的个数,初始化都为0。读入后,遇到雷就把周围的格子都加一。最后把不是雷的地方都看一遍,看看是否和记录的相同。

AC代码
#include<cstdio>
#include<cstring>
#include<iostream>
#include<algorithm>
#include<cmath>
#include<vector>
#include<set>
#include<string>
#include<sstream>
#include<cctype>
#include<map>
#include<stack>
#include<queue>
#include<list>
#include<cstdlib>
#include<ctime>
using namespace std;
typedef long long ll;
const int INF = 0x3f3f3f3f;
const ll LL_INF = 0x3f3f3f3f3f3f3f3f;
const ll MOD = 1000000007;

const int maxn = 100010;
char s[maxn];
int a[52];
int n, len;

int readin()
{
    scanf("%s", s);
    len = strlen(s);
    memset(a, 0, sizeof(a));
    for(int i = 0; i < len; i++)
    {
        if(s[i] >= 'a' && s[i] <= 'z')
            a[s[i] - 'a']++;
        else
            a[s[i] - 'A' + 26]++;
    }
    int mx = 0;
    for(int i = 0; i < 52; i++)
    {
        if(a[i] > mx)
            mx = a[i];
    }
    if(mx == len && n == 1)
        mx = mx - 1;
    else
        mx = min(len, mx + n);
    return mx;
}

int main()
{
//    freopen("input.txt", "r", stdin);
//    freopen("output.txt", "w", stdout);
    int x, y, z;
    scanf("%d", &n);

    x = readin();
    y = readin();
    z = readin();

    int ans[3] = {x, y, z};
    sort(ans, ans + 3);
    if(ans[2] == ans[1])
    {
        printf("Draw\n");
    }
    else
    {
        if(ans[2] == x)
            printf("Kuro\n");
        else if(ans[2] == y)
            printf("Shiro\n");
        else
            printf("Katie\n");
    }
    return 0;
}
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值