7.18 热身赛 Game
Game
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/65536 K (Java/Others)Total Submission(s): 102 Accepted Submission(s): 40
Problem Description
Alice and Bob are playing a game. They take turns and Alice moves first. There is a set of positive integers. In one’s turn, he or she can choose a number (suppose x) in the set, and choose a positive integer k (k does not need to be in the set), and replace x with x−(10k−1). For example, you can make a number x in the set become x−9 or x−99 or x−999 or x−999⋯. After that the set must still be a set of positive integers. That is to say:
* The number must still be positive: x−(10k−1)>0.
* A set can not have duplicate elements: x−(10k−1) can not be equal to any other numbers in the set.
They take turns and Alice moves first. The one who can’t move loses the game. Now the question is that who will win the game if they play optimally.
Input
There are multiple test cases.
For each test case, the first line contains a number N, denoting the number of numbers in the set.
The second line contains N different positive integers A1,A2,…,AN, denoting the numbers in the set.
It’s guaranteed that 1≤Ai≤109, and the sum of N of all test cases is not larger than 2⋅105.
Output
For each test case, print”A’’ for Alice or ”B’’ for Bob in one line, denoting the winner.
Sample Input
3
1 2 3
3
2 11 20
3
11 12 13
3
10 19 28
2
100 1000
Sample Output
B
B
A
A
A
大概题意
进行游戏,两人轮流操作,用x−(10k−1)替代集合中x(k为任意正整数,x−(10k−1) > 0),注意保证集合中元素的互异性,先无法操作者输。
思路
“用x−(10k−1)替代集合中x” 即x - 9,99,999,9999…….故游戏结果必为原集合中元素 mod 9的结果(保证互异性),将这些数按 mod 9结果分组,统计操作数,操作数为奇数,则先手胜,反之后手胜。
代码
//
// Created by Black on 2021/7/18.
//
#include <iostream>
#include <cstdio>
#include <vector>
#include <algorithm>
using namespace std;
int t, n, m;
const int N = 100010;
int main() {
while (scanf("%d", &t) != -1) {
int a[N];
vector<int> b[10];
for (int i = 0; i < t; ++i) {
cin >> a[i];
b[a[i] % 9].push_back(a[i]);
}
int res = 0;
for (int i = 1; i < 9; ++i) {
sort(b[i].begin(), b[i].end());
for (int j = 0; j < b[i].size(); ++j) {
if (b[i][j] / 9 - j > 0)
res += b[i][j] / 9 - j;
}
}
//按照要求,结果应大于0,故单独计算能整除9的元素组
for (int i = 0; i < b[0].size(); ++i) {
if (b[0][i] / 9 - 1 - i > 0)
res += b[0][i] / 9 - 1 - i;
}
if (res % 2)cout << "A" << endl;
else cout << "B" << endl;
}
return 0;
}
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· 单线程的Redis速度为什么快?
· 展开说说关于C#中ORM框架的用法!
· Pantheons:用 TypeScript 打造主流大模型对话的一站式集成库
· SQL Server 2025 AI相关能力初探
· 为什么 退出登录 或 修改密码 无法使 token 失效