URAL 1715. Another Ball Killer (大模拟)

本文详细解析了一款名为AnotherBallKiller的游戏规则,并通过模拟实现了游戏过程中的各种操作及计分方式。游戏在一个n×m的矩形区域内进行,玩家需要消除相连的相同颜色球体来获得分数。

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

1715. Another Ball Killer

Time limit: 2.0 second
Memory limit: 64 MB
Contestants often wonder what jury members do during a contest. Someone thinks that they spend all the contest fixing bugs in tests. Others say that the jury members watch the contest excitedly and even bet on who will win. However, in reality, the jury members prefer to play computer games, giving a complete control of the contest to heartless machines.
Another Ball Killer is one of the favorite games of the jury. Its rules are very simple:
  1. The game is played by one person on a rectangular field of size n × m. At the initial moment, each cell of the field contains a ball of one of five colors: blue, green, red, white, or yellow.
  2. At each move, the player chooses some figure (a connected group of two or more balls of the same color; balls are called connected if their cells have a common side) and removes it from the field. After that the balls that were above the removed balls fall down. If a column without the balls appears, then all the columns on its right are shifted to the left. 
    The image below shows how the field changes after the removal of the largest figure. 
    The player is awarded k × (k − 1) points for his move, where k is the size of the removed figure, i.e. the number of balls in it.
  3. The game is finished when there are no figures left on the field. The goal is to get as many points as possible by the end of the game.
Problem illustration
Lazy jury members play Another Ball Killer using the following algorithm:
01  Choose the color of one of the balls in the field as the main color.
02  While there is at least one figure:
03      While there is at least one figure of a color different from the main color:
04          Remove the largest figure of a color different from the main color.
05      If there is a figure of the main color:
06          Remove the largest figure of the main color.
If there are several ways to remove the figure in lines 04 and 06, one should choose the largest figure containing the bottommost ball (if there are several such figures, then one should choose among them the figure that contains the leftmost of such balls).
Chairman is the laziest person in the jury. He doesn't even think about which color he should choose as the main one. By pressing one key, he launches a program that calculates for every color present in the field the number of points that will be awarded if this color is chosen as the main one. Your task is to write such a program.

Input

The first line contains the dimensions of the field n and m (1 ≤ nm ≤ 50). Each of the followingn lines contains m letters denoting the color of the ball in the corresponding cell of the field (B for blue, G for green, R for red, W for white, and Y for yellow). The rows of the playing field are given in the order from the top row to the bottom row.

Output

Output one line for each color present in the field: first output the letter denoting the color, then a colon, a space, and the number of points the chairman of the jury will get if he chooses this color as the main one. The colors must be considered in the following order: blue, green, red, white, yellow.

Sample

input output
3 6
WWWGBG
WBGGGB
GGGGBB
B: 74
G: 92
W: 74
Problem Author: folklore (prepared by Eugene Krokhalev)
Problem Source: NEERC 2009, Eastern subregional contest


题意:n*m的格子上有至多5种颜色的格子,同一颜色的 k (k>=2)个格子连成一块可以相消,得分k*(k-1),每次规定一主颜色,每次先消最大的块,若存在多个相同大小的块,先消靠底部的,靠左边的;先消与主颜色不同的块,再消主颜色的块。每次消完一个块整体都向下挪,向左挪,如题图。输出每种主颜色下的得分。

思路:蛋疼大模拟,敲了两个小时,脑袋都要炸了,幸好1A哭感激涕零,直接上代码,自己的代码写完就看不懂了=-=

代码:

#include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <cmath>
#include <string>
#include <map>
#include <stack>
#include <vector>
#include <set>
#include <queue>
#pragma comment (linker,"/STACK:102400000,102400000")
#define pi acos(-1.0)
#define eps 1e-6
#define lson rt<<1,l,mid
#define rson rt<<1|1,mid+1,r
#define FRE(i,a,b)  for(i = a; i <= b; i++)
#define FREE(i,a,b) for(i = a; i >= b; i--)
#define FRL(i,a,b)  for(i = a; i < b; i++)
#define FRLL(i,a,b) for(i = a; i > b; i--)
#define mem(t, v)   memset ((t) , v, sizeof(t))
#define sf(n)       scanf("%d", &n)
#define sff(a,b)    scanf("%d %d", &a, &b)
#define sfff(a,b,c) scanf("%d %d %d", &a, &b, &c)
#define pf          printf
#define DBG         pf("Hi\n")
typedef long long ll;
using namespace std;

#define INF 0x3f3f3f3f
#define mod 1000000009

const int maxn = 55;

int a[26];
int n,m,cnt;
char mp[maxn][maxn],MP[maxn][maxn];
bool vis[maxn][maxn];
bool ok1[maxn][maxn],ok2[maxn][maxn];
int dir[4][2]={1,0,0,1,-1,0,0,-1};

void show()
{
    for (int i=0;i<n;i++)
        printf("%s\n",mp[i]);
}

bool isok(int x,int y)
{
    if (x>=0&&x<n&&y>=0&&y<m) return true;
    return false;
}

int dis_up(int x,int y)
{
    int ans=0;
    while (isok(x,y)&&mp[x][y]=='.')
    {
        ans++;
        x--;
    }
    return ans;
}

void Change(int x,int y)
{
     for(int i=x;i>=0;i--)
        if(i==0) mp[i][y]='.';
     else
        mp[i][y]=mp[i-1][y];
}

void Move(int y)
{
    int i,j;
    for(i=0;i<n;i++)
        if(mp[i][y]=='.')
           Change(i,y);
}

void right_to_left(int y)
{
    for (int i=0;i<n;i++)
    {
        for (int j=y;j<m-1;j++)
        {
            mp[i][j]=mp[i][j+1];
        }
        mp[i][m-1]='.';
    }
}

void dfs(int x,int y,int letter)
{
    ok1[x][y]=true;
    vis[x][y]=true;
    cnt++;
    for (int i=0;i<4;i++)
    {
        int dx=dir[i][0]+x;
        int dy=dir[i][1]+y;
        if (isok(dx,dy)&&!vis[dx][dy]&&mp[dx][dy]==letter)
            dfs(dx,dy,letter);
    }
    return ;
}

int ffd(int color,int wq)
{
    memset(vis,false,sizeof(vis));
    int number=0;
    for (int i=n-1;i>=0;i--)
    {
        for (int j=0;j<m;j++)
        {
            if (mp[i][j]=='.') continue;
            if (vis[i][j]) continue;
            if (wq==1&&mp[i][j]=='A'+color) continue;
            else if (wq==0&&mp[i][j]!='A'+color) continue;
            cnt=0;
            memset(ok1,false,sizeof(ok1));
            dfs(i,j,mp[i][j]);
            if (cnt<2) continue;
            if (cnt>number)
            {
                number=cnt;
                memcpy(ok2,ok1,sizeof(ok1));
            }
        }
    }
    return number;
}

void change()
{
    for (int i=0;i<n;i++)
    {
        for (int j=0;j<m;j++)
            if (ok2[i][j])
            mp[i][j]='.';
    }
//    printf("******\n");
//    show();
//    printf("******\n\n");
    for (int j=0;j<m;j++)
    {
        Move(j);
    }
    for (int j=m-1;j>=0;j--)
    {
        int x=dis_up(n-1,j);
        if (x==n)
            right_to_left(j);
    }

}

int get_point(int color)
{
    int sum=0;
    while (1)
    {
        int ss;
        while ((ss=ffd(color,1))>=2)
        {
//            printf("ss=%d\n",ss);
//            cas++;
            sum+=(ss-1)*ss;
            change();
//            show();
//            printf("==================\n");
        }
        if ((ss=ffd(color,0))>=2)
        {
            sum+=(ss-1)*ss;
            change();
//            show();
//            printf("++++++++++++++++++++\n");
        }
        if (ffd(color,1)<2&&ffd(color,0)<2) break;
    }
    return sum;
}

void solve()
{
    for (int i=0;i<26;i++)
    {
        if (a[i])
        {
            memcpy(mp,MP,sizeof(MP));
            int sum=get_point(i);
            printf("%c: %d\n",'A'+i,sum);
        }
    }
}

int main()
{
    int i,j;
    while (~scanf("%d%d",&n,&m))
    {
        memset(a,0,sizeof(a));
        for (i=0;i<n;i++)
        {
            scanf("%s",mp[i]);
            for (j=0;j<m;j++)
                a[mp[i][j]-'A']=1;
        }
        memcpy(MP,mp,sizeof(mp));
        solve();
    }
    return 0;
}



内容概要:该研究通过在黑龙江省某示范村进行24小时实地测试,比较了燃煤炉具与自动/手动进料生物质炉具的污染物排放特征。结果显示,生物质炉具相比燃煤炉具显著降低了PM2.5、CO和SO2的排放(自动进料分别降低41.2%、54.3%、40.0%;手动进料降低35.3%、22.1%、20.0%),但NOx排放未降低甚至有所增加。研究还发现,经济性和便利性是影响生物质炉具推广的重要因素。该研究不仅提供了实际排放数据支持,还通过Python代码详细复现了排放特征比较、减排效果计算和结果可视化,进一步探讨了燃料性质、动态排放特征、碳平衡计算以及政策建议。 适合人群:从事环境科学研究的学者、政府环保部门工作人员、能源政策制定者、关注农村能源转型的社会人士。 使用场景及目标:①评估生物质炉具在农村地区的推广潜力;②为政策制定者提供科学依据,优化补贴政策;③帮助研究人员深入了解生物质炉具的排放特征和技术改进方向;④为企业研发更高效的生物质炉具提供参考。 其他说明:该研究通过大量数据分析和模拟,揭示了生物质炉具在实际应用中的优点和挑战,特别是NOx排放增加的问题。研究还提出了多项具体的技术改进方向和政策建议,如优化进料方式、提高热效率、建设本地颗粒厂等,为生物质炉具的广泛推广提供了可行路径。此外,研究还开发了一个智能政策建议生成系统,可以根据不同地区的特征定制化生成政策建议,为农村能源转型提供了有力支持。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值