气球消消乐(二)(选做)

 

#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll mod=1e12+7;
ll mul(ll a,ll b)
{
    ll sum=0;
    while(b)
    {
        if(b%2==1)
            sum=(sum+a)%mod;
        a=(a+a)%mod;
        b=b/2;
    }
    return sum;
}
ll pre(ll a,ll b)
{
    ll ans=1;
    while(b)
    {
        if(b%2==1)
            ans=mul(ans,a)%mod;
        a=mul(a,a)%mod;
        b=b/2;
    }
    return ans;
}
int main()
{
    ll n,m;
    cin>>n>>m;
    cout<<(pre(m,n)-mul(pre(m-1,n-1),m)+mod)%mod<<endl;
    return 0;
}

 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
消消乐是一种经典的益智游戏,玩家需要通过消除相同颜色的方块来获得分数。下面是一个用Python实现消消乐游戏的简单示例: ```python import random # 游戏区域大小 ROWS = 8 COLS = 8 # 方块颜色 COLORS = ['R', 'G', 'B', 'Y'] # 创建游戏区域 board = [[random.choice(COLORS) for _ in range(COLS)] for _ in range(ROWS)] # 打印游戏区域 def print_board(): for row in board: print(' '.join(row)) print() # 消除相同颜色的方块 def eliminate(row, col, color): if row < 0 or row >= ROWS or col < 0 or col >= COLS or board[row][col] != color: return 0 count = 1 board[row][col] = '' count += eliminate(row-1, col, color) count += eliminate(row+1, col, color) count += eliminate(row, col-1, color) count += eliminate(row, col+1, color) return count # 消除所有相同颜色的方块 def eliminate_all(): total_count = 0 for row in range(ROWS): for col in range(COLS): if board[row][col] != '': count = eliminate(row, col, board[row][col]) if count > 1: total_count += count return total_count # 主循环 while True: print_board() score = eliminate_all() print(f"Score: {score}") if score == 0: print("Game Over") break # 重新填充空缺的方块 for col in range(COLS): empty_count = sum(1 for row in range(ROWS) if board[row][col] == '') if empty_count > 0: for row in range(ROWS-1, -1, -1): if board[row][col] == '': board[row][col] = random.choice(COLORS) empty_count -= 1 if empty_count == 0: break ``` 这个示例中,我们使用维列表来表示游戏区域,每个元素代表一个方块的颜色。通过递归函数`eliminate`来消除相同颜色的方块,并计算消除的总数。然后,我们在主循环中不断打印游戏区域、消除方块并重新填充空缺的方块,直到没有可以消除的方块为止。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值