【题解】游戏(game)注:这个游戏不是c++小游戏!!!

输入样例:

5 6 100
1 3 2 2 1
3 3 1 1 1 2

输出样例:

29

乍一看,还以为是枚举,一瞅K的范围,想了想,才晓得是数学周期问题。

也不难,只要求出一个周期赢几次,接着求剩下的,加起来,输出就没了。

上代码!

#include<bits/stdc++.h>
using namespace std;
int n,m,k,a[102005],b[102005],s,ans;
int main(){
	ios::sync_with_stdio(false);
	cin.tie(NULL);
	cout.tie(NULL);
	cin>>n>>m>>k;
	for(int i=1;i<=n;i++) cin>>a[i];             //读入
	for(int i=1;i<=m;i++) cin>>b[i];
	for(int i=1;i<=n*m;i++){               //一个周期ps:一个周期原来要用公倍数的,我懒,没用……
		if(a[i]==1&&b[i]==2||a[i]==2&&b[i]==3||a[i]==3&&b[i]==1) s++;
		a[i+n]=a[i],b[i+m]=b[i];           //把比较完的放到最后,就是死循环了(除非内存BOOM炸了)
	}
	ans=k/(n*m)*s;                         //ans是答案
	for(int i=1;i<=k%(n*m);i++){                 //求剩下的     ↑上面复制一下↑
		if(a[i]==1&&b[i]==2||a[i]==2&&b[i]==3||a[i]==3&&b[i]==1) /*这里的s改成ans*/ans++;
		a[i+n]=a[i],b[i+m]=b[i];
	}
	cout<<ans;
	return 0;
}

代码不长的,主要是你想到没……

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
你好!对于扫雷游戏题解,我可以给你一些思路和代码示例。首先,你需要了解扫雷游戏则和要求。接下来,你可以使用C++语言来实现游戏逻辑和界面。 下面是一个简单的扫雷游戏C++代码示例: ```cpp #include <iostream> #include <vector> #include <random> using namespace std; class MinesweeperGame { private: int rows; int cols; vector<vector<char>> board; vector<vector<bool>> revealed; vector<pair<int, int>> directions = {{-1, -1}, {-1, 0}, {-1, 1}, {0, -1}, {0, 1}, {1, -1}, {1, 0}, {1, 1}}; public: MinesweeperGame(int m, int n, int mineCount) { rows = m; cols = n; board.resize(rows, vector<char>(cols, ' ')); revealed.resize(rows, vector<bool>(cols, false)); placeMines(mineCount); calculateNumbers(); } void printBoard() { cout << " "; for (int j = 0; j < cols; j++) { cout << j << " "; } cout << endl; for (int i = 0; i < rows; i++) { cout << i << " |"; for (int j = 0; j < cols; j++) { cout << board[i][j] << "|"; } cout << endl; } } bool isGameOver() { for (int i = 0; i < rows; i++) { for (int j = 0; j < cols; j++) { if (board[i][j] == 'M' && revealed[i][j]) { return true; } } } return false; } void reveal(int row, int col) { if (row < 0 || row >= rows || col < 0 || col >= cols || revealed[row][col]) { return; } revealed[row][col] = true; if (board[row][col] == 'M') { return; } if (board[row][col] == '0') { for (auto dir : directions) { reveal(row + dir.first, col + dir.second); } } } private: void placeMines(int mineCount) { random_device rd; mt1
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值