2025.1.24——1400
2025.1.24——1400
A 1400
Two players are playing an online card game. The game is played using a 32-card deck. Each card has a suit and a rank. There are four suits: clubs, diamonds, hearts, and spades. We will encode them with characters 'C', 'D', 'H', and 'S', respectively. And there are 8 ranks, in increasing order: '2', '3', '4', '5', '6', '7', '8', '9'.
Each card is denoted by two letters: its rank and its suit. For example, the 8 of Hearts is denoted as 8H.
At the beginning of the game, one suit is chosen as the trump suit.
In each round, players make moves like this: the first player places one of his cards on the table, and the second player must beat this card with one of their cards. After that, both cards are moved to the discard pile.
A card can beat another card if both cards have the same suit and the first card has a higher rank than the second. For example, 8S can beat 4S. Additionally, a trump card can beat any non-trump card, regardless of the rank of the cards, for example, if the trump suit is clubs ('C'), then 3C can beat 9D. Note that trump cards can be beaten only by the trump cards of higher rank.
There were
Input
The first line contains integer
The first line of a test case contains the integer number
The second line of a test case contains one character, the trump suit. It is one of "CDHS".
The third line of a test case contains the description of
B 1400
You are given an array
Process all
- First, output the remainder of the product of all elements of the array
when divided by . - Then, if the command is 'L', remove the leftmost element from the array
, if the command is 'R', remove the rightmost element from the array .
Note that after each move, the length of the array
Write a program that will process all commands in the order they are written in the string
Input
The first line contains an integer
Each test case of the input is given by three lines.
The first line contains two integers
The second line contains
The third line contains a string
It is guaranteed that the sum of the values of
C 1400
Sasha gave Anna a list
Players take turns. Sasha is a gentleman, so he gives Anna the right to make the first move.
- On her turn, Anna must choose an element
from the list and reverse the sequence of its digits. For example, if Anna chose the element with a value of , it would become ; if Anna chose the element with a value of , it would become . Note that leading zeros are removed. After such a turn, the number of elements in the list does not change. - On his turn, Sasha must extract two elements
and ( ) from the list, concatenate them in any order and insert the result back into the list. For example, if Sasha chose the elements equal to and , he would remove these two elements from the list and add the integer or . After such a turn, the number of elements in the list decreases by .
Players can't skip turns. The game ends when Sasha can't make a move, i.e. after Anna's move there is exactly one number left in the list. If this integer is not less than
It can be shown that the game will always end. Determine who will win if both players play optimally.
Input
The first line contains an integer
Then follows the description of the test cases.
The first line of each test case contains integers
The second line of each test case contains
It is guaranteed that the sum of
D 1400
Sasha decided to give his girlfriend the best handbag, but unfortunately for Sasha, it is very expensive. Therefore, Sasha wants to earn it. After looking at earning tips on the internet, he decided to go to the casino.
Sasha knows that the casino operates under the following rules. If Sasha places a bet of
Note that the bet amount must always be a positive (
Sasha also knows that there is a promotion at the casino: he cannot lose more than
Initially, Sasha has
Input
Each test consists of multiple test cases. The first line contains a single integer
The single line of each test case contains three integers
------------------------思考------------------------
-
模拟+思维+贪心/博弈+赌博(
A
- 模拟,唯一注意点就是
和函数的使用可以使过程简化。
B
- 删除操作较难维护(需要线段树),逆向思维发现添加操作较易维护。
C
- 发现两人的操作本质都是保护/删除一个数后导0的个数。排序贪心。
D
- 这个有点灵光一现。当前局下注的筹码在获胜情况下可以把所有输的都赢回来,直到必胜局,判断原有筹码是否足够。注意循环下来可能爆long long,提前结束。
------------------------代码------------------------
A
#include <bits/stdc++.h>
#define int long long //
#define endl '\n' // attention: interactive/debug
#define el cout << endl
using namespace std;
#define bug(BUG) cout << "bug:# " << (BUG) << endl
#define bug2(BUG1, BUG2) cout << "bug:# " << (BUG1) << " " << (BUG2) << endl
#define bug3(BUG1, BUG2, BUG3) cout << "bug:# " << (BUG1) << ' ' << (BUG2) << ' ' << (BUG3) << endl
#define bugv(VEC, ST) \
{ \
for (int I = ST; I < VEC.size(); I++) \
cout << VEC[I] << ' '; \
el; \
}
void _();
signed main()
{
ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);
cout << fixed << setprecision(10);
int T = 1;
cin >> T;
while (T--)
_();
return 0;
}
void _()
{
int n;
char op;
set<string> C, D, H, S;
cin >> n >> op;
for (int i = 0; i < n << 1; i++)
{
string t;
cin >> t;
if (t[1] == 'C')
C.insert(t);
else if (t[1] == 'D')
D.insert(t);
else if (t[1] == 'H')
H.insert(t);
else
S.insert(t);
}
vector<string> res;
bool has = 1;
auto f = [&](set<string> &mx, set<string> &a)
{
while (a.size())
{
res.push_back(*a.begin());
a.erase(a.begin());
if (a.size())
{
res.push_back(*a.begin());
a.erase(a.begin());
}
else
{
if (mx.size())
{
res.push_back(*mx.begin());
mx.erase(mx.begin());
}
else
has = 0;
}
}
};
auto get = [&](set<string> mx, set<string> a, set<string> b, set<string> c)
{
f(mx, a);
f(mx, b);
f(mx, c);
while (mx.size())
{
res.push_back(*mx.begin());
mx.erase(mx.begin());
}
};
if (op == 'C')
get(C, H, S, D);
else if (op == 'D')
get(D, C, H, S);
else if (op == 'H')
get(H, C, D, S);
else if (op == 'S')
get(S, C, H, D);
if (!has)
{
cout << "IMPOSSIBLE";
el;
return;
}
for (int i = 0; i < n << 1; i += 2)
cout << res[i] << ' ' << res[i + 1] << endl;
}
B
#include <bits/stdc++.h>
#define int long long //
#define endl '\n' // attention: interactive/debug
#define el cout << endl
using namespace std;
#define bug(BUG) cout << "bug:# " << (BUG) << endl
#define bug2(BUG1, BUG2) cout << "bug:# " << (BUG1) << " " << (BUG2) << endl
#define bug3(BUG1, BUG2, BUG3) cout << "bug:# " << (BUG1) << ' ' << (BUG2) << ' ' << (BUG3) << endl
#define bugv(VEC, ST) \
{ \
for (int I = ST; I < VEC.size(); I++) \
cout << VEC[I] << ' '; \
el; \
}
void _();
signed main()
{
ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);
cout << fixed << setprecision(10);
int T = 1;
cin >> T;
while (T--)
_();
return 0;
}
void _()
{
int n, m;
cin >> n >> m;
vector<int> a(n + 1);
for (int i = 1; i <= n; i++)
cin >> a[i];
string s;
cin >> s;
int l = 1, r = n;
for (int i = 0; i < n - 1; i++)
{
if (s[i] == 'L')
l++;
else
r--;
}
int ans = a[l] % m;
vector<int> res{ans};
for (int i = n - 2; i >= 0; i--)
{
if (s[i] == 'L')
l--, ans = ans * a[l] % m;
else
r++, ans = ans * a[r] % m;
res.push_back(ans);
}
reverse(res.begin(), res.end());
bugv(res, 0);
}
// void _()
// {
// int n, m;
// cin >> n >> m;
// vector<int> a(n + 1);
// for (int i = 1; i <= n; i++)
// cin >> a[i];
// string s;
// cin >> s;
// // ST表 RMQ 倍增
// // 查询区间最大值 静态查询 线段树可以修改
// // dp[i][j] 以i为起点 长度为1<<j的区间的最大值
// vector<vector<int>> dp(n + 1, vector<int>(32)); // 内存超限 必要时关long long
// // init
// for (int j = 0; j < 30; j++) // j 是每一层状态
// for (int i = 1; i <= n; i++)
// {
// if (i + (1 << j) - 1 > n)
// continue;
// if (!j)
// dp[i][j] = a[i];
// else
// dp[i][j] = dp[i][j - 1] * dp[i + (1 << j - 1)][j - 1];
// }
// // query
// auto ask = [&](int l, int r)
// {
// int k = log(r - l + 1) / log(2);
// return dp[l][k] * dp[r + 1 - (1 << k)][k];
// };
// bugv(a, 1);
// for (int i = 1; i <= n; i++)
// for (int j = 1; j <= i; j++)
// bug3(i, j, ask(i, j));
// // int l, r;
// // l = 1, r = n;
// // for (int i = 0; i < n; i++)
// // {
// // cout << ask(l, r) << ' ';
// // if (s[i] == 'L')
// // l++;
// // else
// // r++;
// // }
// // el;
// }
C
#include <bits/stdc++.h>
#define int long long //
#define endl '\n' // attention: interactive/debug
#define el cout << endl
using namespace std;
#define bug(BUG) cout << "bug:# " << (BUG) << endl
#define bug2(BUG1, BUG2) cout << "bug:# " << (BUG1) << " " << (BUG2) << endl
#define bug3(BUG1, BUG2, BUG3) cout << "bug:# " << (BUG1) << ' ' << (BUG2) << ' ' << (BUG3) << endl
#define bugv(VEC, ST) \
{ \
for (int I = ST; I < VEC.size(); I++) \
cout << VEC[I] << ' '; \
el; \
}
void _();
signed main()
{
ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);
cout << fixed << setprecision(10);
int T = 1;
cin >> T;
while (T--)
_();
return 0;
}
void _()
{
int n, m;
cin >> n >> m;
int digs = 0;
vector<int> dig_0s;
auto cal = [&](int x)
{
int dig_0 = 0;
bool zero = 1;
while (x)
{
if (x % 10 == 0 && zero)
dig_0++;
else
zero = 0;
digs++;
x /= 10;
}
dig_0s.push_back(dig_0);
};
for (int i = 0; i < n; i++)
{
int x;
cin >> x;
cal(x);
}
sort(dig_0s.rbegin(), dig_0s.rend());
for (int i = 0; i < dig_0s.size(); i += 2)
digs -= dig_0s[i];
cout << (digs > m ? "Sasha" : "Anna");
el;
}
D
#include <bits/stdc++.h>
#define int long long //
#define endl '\n' // attention: interactive/debug
#define el cout << endl
using namespace std;
#define bug(BUG) cout << "bug:# " << (BUG) << endl
#define bug2(BUG1, BUG2) cout << "bug:# " << (BUG1) << " " << (BUG2) << endl
#define bug3(BUG1, BUG2, BUG3) cout << "bug:# " << (BUG1) << ' ' << (BUG2) << ' ' << (BUG3) << endl
#define bugv(VEC, ST) \
{ \
for (int I = ST; I < VEC.size(); I++) \
cout << VEC[I] << ' '; \
el; \
}
void _();
signed main()
{
ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);
cout << fixed << setprecision(10);
int T = 1;
cin >> T;
while (T--)
_();
return 0;
}
void _()
{
int k, x, a;
cin >> k >> x >> a;
int has = 0;
for (int i = 1; i <= x + 1; i++)
{
int t = (has + k - 1) / (k - 1);
// bug2(i, t);
has += t;
if (has > a)
{
cout << "NO";
el;
return;
}
}
// bug(has);
cout << (a >= has ? "YES" : "NO");
el;
}
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· 10年+ .NET Coder 心语 ── 封装的思维:从隐藏、稳定开始理解其本质意义
· 地球OL攻略 —— 某应届生求职总结
· 周边上新:园子的第一款马克杯温暖上架
· 提示词工程——AI应用必不可少的技术
· Open-Sora 2.0 重磅开源!