Mooyo Mooyo [洛谷] (模拟) /*rank*/

本文介绍了一个名为Mooyo Mooyo的游戏,类似人类的Puyo Puyo。游戏在N×10的网格上进行,玩家需处理不同颜色的haybales形成连接区域,当区域大小达到K时会消失。题目描述了输入输出格式,并提供了模拟消除过程的思路,包括检查、消除和重力下落的步骤,直至没有可消除的连接区域。

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

原题传送门


题面:

Mooyo Mooyo

                              time limit per test : 1 second
                           memory limit per test : 256 megabytes
                                  input : standard input
                                 output : standard output

Problem Description

With plenty of free time on their hands (or rather, hooves), the cows on Farmer John’s farm often pass the time by playing video games. One of their favorites is based on a popular human video game called Puyo Puyo; the cow version is of course called Mooyo Mooyo. The game of Mooyo Mooyo is played on a tall narrow grid N cells tall (1≤N≤100) and 10 cells wide. Here is an example with N=6:
0000000000
0000000300
0054000300
1054502230
2211122220
1111111223
Each cell is either empty (indicated by a 0), or a haybale in one of nine different colors (indicated by characters 1…9). Gravity causes haybales to fall downward, so there is never a 0 cell below a haybale.

Two cells belong to the same connected region if they are directly adjacent either horizontally or vertically, and they have the same nonzero color. Any time a connected region exists with at least K cells, its haybales all disappear, turning into zeros. If multiple such connected regions exist at the same time, they all disappear simultaneously. Afterwards, gravity might cause haybales to fall downward to fill some of the resulting cells that became zeros. In the resulting configuration, there may again be connected regions of size at least K cells. If so, they also disappear (simultaneously, if there are multiple such regions), then gravity pulls the remaining cells downward, and the process repeats until no connected regions of size at least K exist.

Given the state of a Mooyo Mooyo board, please output a final picture of the board after these operations have occurred.

Input

The first line of input contains N and K(1≤K≤10N). The remaining N lines specify the initial state of the board.

Output

Please output N lines, describing a picture of the final board state.

Sample Input

6 3
0000000000
0000000300
0054000300
1054502230
2211122220
1111111223

Sample Output

0000000000
0000000000
0000000000
0000000000
1054000000
2254500000

题意描述

当某一个数字形成的块内数字的个数大于等于K的时候,就会整个块消失.并且存在重力,即非0数字下面若是0,则非0数字会往下走,直到到底或者遇上非0数字.要求输出最终形成的图.

题目分析

直接模拟.进行检查,看图内有没有数字块内数字个数是大于等于K的,有则标记上,图遍历完之后进行消除被标记的块,然后进行重力交换处理.接着再检查图内有没有需要消除的块,直到图内没有需要消除的块为止.

具体代码

#include <iostream>
#include <bits/stdc++.h>
using namespace std;
typedef pair < int , int > pii;
char MAP[105][15];
bool flag[105][15];
int cx[4]={0,1,0,-1}, cy[4]={1,0,-1,0};
int N, K, cnt;

void DFS(int sx, int sy)
{
    if(sx < 0 || sy < 0 || sx >= N || sy >= 10)
    {
        return;
    }
    for(int i = 0; i < 4 ; i++)
    {
        int xx = sx+cx[i];
        int yy = sy+cy[i];
        if(MAP[xx][yy] == MAP[sx][sy] && !flag[xx][yy])
        {
            cnt++;
            flag[xx][yy] = true;
            DFS(xx , yy);
        }
    }
}

void del()
{
    for(int i = 0; i < N; i++)
    {
        for(int j = 0; j < 10; j++)
        {
            if(flag[i][j])
            {
                MAP[i][j] = '0';
            }
        }
    }
}

void solve()
{
    bool mark = true;
    for(int i = 0; i < N; i++)
    {
        for(int j = 0; j < 10; j++)
        {
            if(MAP[i][j] != '0' && !flag[i][j])
            {
                memset(flag, 0, sizeof(flag));
                cnt = 0;
                DFS(i , j);
                if(cnt >= K)
                {
                    mark = false;
                    del();
                }
            }
        }
    }
    for(int j = 0; j < 10; j++)
    {
        for(int i = N-1; i >= 0; i--)
        {
            if(MAP[i][j] == '0')
            {
                int t = i;
                while(MAP[t][j] == '0' && t >= 0)
                {
                    t--;
                }
                if(t < 0)
                {
                    break;
                }
                MAP[i][j] = MAP[t][j];
                MAP[t][j] = '0';
            }
        }
    }
    if(!mark)
    {
        solve();
    }
}

int main()
{
    scanf("%d%d", &N, &K);
    for(int i = 0; i < N; i++)
    {
        scanf("%s", MAP[i]);
    }
    solve();
    for(int i = 0; i < N; i++)
    {
        printf("%s\n", MAP[i]);
    }
    return 0;
}
public class CompetitionUserInfoPo { /** * 主键 */ private Long id; /** * 渠道 */ private String channel; /** * 机构编号 */ private String deptId; /** * 机构名称 */ private String deptName; /** * 推广组号 */ private String groupId; /** * 用户ID */ private String userId; /** * 用户名 */ private String userName; /** * 单人比赛次数 */ private Integer singleCompetitionTimes; /** * 单人获胜次数 */ private Integer singleWinCount; /** * 单人失败次数 */ private Integer singleLoseCount; /** * 单人平局次数 */ private Integer singleDrawCount; /** * 担任队长次数 */ private Integer leaderCount; /** * 团队比赛次数 */ private Integer teamCompetitionTimes; /** * 团队获胜次数 */ private Integer teamWinCount; /** * 团队失败次数 */ private Integer teamLoseCount; /** * 团队平局次数 */ private Integer teamDrawCount; /** * 个人赛连胜次数 */ private Integer singleWinStreak; /** * 团队赛连胜次数 */ private Integer teamWinStreak; /** * 单人比赛积分 */ private Integer singleCompetitionPoints; /** * 团队 PK 赛积分 */ private Integer teamCompetitionPoints; /** * 总比赛积分 */ private Integer totalCompetitionPoints; /** * 获得点赞数 */ private Integer likedCount; /** * 是否有效 */ private Integer valid; /** * 创建时间 */ private Date createTime; /** * 更新时间 */ private Date updateTime; } public class GetHeroRankListPo { /** * 主键 */ private Long id; /** * 渠道 */ private String channel; /** * 机构编号 */ private String deptId; /** * 机构名称 */ private String deptName; /** * 推广组号 */ private String groupId; /** * 用户ID */ private String userId; /** * 用户名 */ private String userName; /** * 单人比赛次数 */ private Integer singleCompetitionTimes; /** * 单人获胜次数 */ private Integer singleWinCount; /** * 单人失败次数 */ private Integer singleLoseCount; /** * 单人平局次数 */ private Integer singleDrawCount; /** * 担任队长次数 */ private Integer leaderCount; /** * 团队比赛次数 */ private Integer teamCompetitionTimes; /** * 团队获胜次数 */ private Integer teamWinCount; /** * 团队失败次数 */ private Integer teamLoseCount; /** * 团队平局次数 */ private Integer teamDrawCount; /** * 个人赛连胜次数 */ private Integer singleWinStreak; /** * 团队赛连胜次数 */ private Integer teamWinStreak; /** * 单人比赛积分 */ private Integer singleCompetitionPoints; /** * 团队 PK 赛积分 */ private Integer teamCompetitionPoints; /** * 总比赛积分 */ private Integer totalCompetitionPoints; /** * 获得点赞数 */ private Integer likedCount; /** * 是否有效 */ private Integer valid; /** * 创建时间 */ private Date createTime; /** * 更新时间 */ private Date updateTime; /** * 胜率 */ private Double winRate; /** * 排名 */ private Integer rank;}对比一下这两个实体类中字段有哪些多了或者少了
07-24
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值