Codeforces Round 939 (Div. 2)
补题连接
A. Nene's Game
题目大意:
给你一个长度为k的序列 a, 然后 q 个询问,每个询问会给出玩家的个数 n,然后每轮我们都会淘汰第 ai个玩家,i\(\in\)[1, k],直至无法再淘汰为止,问剩余多少玩家
分析:
已知量有玩家的个数和序列a,求未知量玩家的剩余个数
假设我们有无穷个玩家,我们每轮都会淘汰第a1、a2、a3、、、ak个玩家,那么什么时候会停止,也就是说当我们玩家的个数小于a序列中所有数的时候我们就无法淘汰, 这个时候才会结束游戏,那么玩家的剩余个数就是\(min(n, a~i~-1)\),ai=\(\sum\limits_{j = 1}^k\min(a~j~)\)
代码:
#include <bits/stdc++.h>
#define int long long
#define all(x) (x).begin(), (x).end()
#define len(x) (x).size()
#define endl '\n'
#define lowbit(x) ((x) & - (x))
#define inv(x, mod) fast_pow(x, mod - 2, mod)
//using namespace std;
const int mod = 1e9 + 7;
const int INF = 0x3f3f3f3f;
void solve() {
int k, q;
std::cin >> k >> q;
std::vector<int> a(k);
for(int i = 0; i < k; i++) {
std::cin >> a[i];
}
int min = *std::min_element(all(a));
while(q--) {
int x;
std::cin >> x;
std::cout << std::min(min - 1, x) << ' ';
}
std::cout << endl;
}
signed main() {
//freopen("input.txt", "r", stdin);
//freopen("output.txt", "w", stdout);
//std::ifstream fin("input.txt");
//std::ofstream fout("output.txt");
std::ios::sync_with_stdio(false);
std::cin.tie(0);
//std::cout.precision(10);
int t = 1;
std::cin >> t;
while (t--) {
solve();
}
return 0;
}
B. Nene and the Card Game
题目大意:
有2n张卡牌,每张卡牌上都有一个1到n的整数,且每个数字都会出现在两张卡牌上,现在将2n张卡牌分成均匀两份给A,B
让A先手出牌,B后手出牌,如果出牌时牌堆里有和所出牌相同数字的牌,则出牌方获得一分
求在双方都最优的情况下,A能获得多少分
分析:
已知量A有的某种牌的数目为2时,B肯定没有,反之依然;A手中的某种牌的数目为1时,B也一样。
那么假设A先出数目为1的种类牌时,B就能马上获得该种牌提供的一分,那么A就可以先出数目为2的种类牌,这一分B必然拿不了
那么如果B出数目为1的种类牌时,A就能马上获得该种牌提供的一分,由于B采取最优,所以也会先出数目为2的种类牌
那么到了此时就是看双方谁手中的数目为2的种类牌先出完,谁就会失去先机被对方吃分
我们设A手中有a种数目为2的牌,B手中有b种数目为2的牌,由于双方手中数目为1的牌的种类必然相同,我们就都设为y
a*2+y=b*2+y
所以双方手中的数目为2的种类牌数相同,由于A先手,所以A会失去y的所有贡献,那么A的最终得分就是手中的数目为2的牌的种类数
代码:
#include <bits/stdc++.h>
#define int long long
#define all(x) (x).begin(), (x).end()
#define len(x) (x).size()
#define endl '\n'
#define lowbit(x) ((x) & - (x))
#define inv(x, mod) fast_pow(x, mod - 2, mod)
//using namespace std;
const int mod = 1e9 + 7;
const int INF = 0x3f3f3f3f;
void solve() {
int n;
std::cin >> n;
std::vector<int> cnt(n + 1);
for(int i = 1; i <= n; i++) {
int x;
std::cin >> x;
cnt[x]++;
}
int ans = 0;
for(int i = 1; i <= n; i++) {
if(cnt[i] == 2)
ans++;
}
std::cout << ans << endl;
}
signed main() {
//freopen("input.txt", "r", stdin);
//freopen("output.txt", "w", stdout);
//std::ifstream fin("input.txt");
//std::ofstream fout("output.txt");
std::ios::sync_with_stdio(false);
std::cin.tie(0);
//std::cout.precision(10);
int t = 1;
std::cin >> t;
while (t--) {
solve();
}
return 0;
}
本文来自博客园,作者:独陷泥沼,感谢您的转载,创作不易,请注明原文链接:https://www.cnblogs.com/hyf-9134/articles/18138697

浙公网安备 33010602011771号