Powered by:NEFU AB-IN
Acwing 第 85 场周赛
-
A AcWing 4791. 死或生
-
题意
略
-
思路
模拟即可
-
代码
#include <bits/stdc++.h> using namespace std; #define int long long #undef int #define SZ(X) ((int)(X).size()) #define ALL(X) (X).begin(), (X).end() #define IOS \ ios::sync_with_stdio(false); \ cin.tie(nullptr); \ cout.tie(nullptr) #define DEBUG(X) cout << #X << ": " << X << '\n' typedef pair<int, int> PII; const int N = 1e5 + 10, INF = 0x3f3f3f3f; int n, cnt11, cnt12, cnt21, cnt22; signed main() { IOS; cin >> n; for (int i = 1; i <= n; ++i) { int t, x, y; cin >> t >> x >> y; if (t == 1) cnt11 += x, cnt12 += y; else cnt21 += x, cnt22 += y; } if (cnt11 >= cnt12) cout << "LIVE\n"; else cout << "DEAD\n"; if (cnt21 >= cnt22) cout << "LIVE\n"; else cout << "DEAD\n"; return 0; }
-
-
B AcWing 4792. 最大价值
-
题意
已知,小写字母 a∼z的价值分别为 wa,wb,…,wz
对于一个由小写字母构成的长度为 l的字符串 S=s1s2…sl,其价值为 ws1×1+ws2×2+…+wsl×l
现在,给定一个由小写字母构成的字符串 S,请你在这个字符串中插入 k 个小写字母,要求最终得到的字符串的价值尽可能大。
输出最大可能价值。 -
思路
贪心 (当时未证明),思路是将k个w最大的放在最后面即可
-
代码
/* * @Author: NEFU AB-IN * @Date: 2023-02-02 18:39:23 * @FilePath: \Acwing\85cp\b\b.cpp * @LastEditTime: 2023-02-02 19:09:55 */ #include <bits/stdc++.h> using namespace std; #define int long long #undef int #define SZ(X) ((int)(X).size()) #define ALL(X) (X).begin(), (X).end() #define IOS \ ios::sync_with_stdio(false); \ cin.tie(nullptr); \ cout.tie(nullptr) #define DEBUG(X) cout << #X << ": " << X << '\n' typedef pair<int, int> PII; const int N = 1e5 + 10, INF = 0x3f3f3f3f; string s; int k, mx; unordered_map<char, int> mp; signed main() { IOS; cin >> s >> k; for (char i = 'a'; i <= 'z'; ++i) { int x; cin >> x; mp[i] = x; mx = max(mx, x); } int ans = 0; for (int i = 0; i < SZ(s); ++i) { ans += (i + 1) * mp[s[i]]; } // DEBUG(ans); for (int i = SZ(s) + 1; i < SZ(s) + 1 + k; ++i) { ans += i * mx; } cout << ans; return 0; }
-
-
C AcWing 4793. 危险程度
-
题意
有 n种化学物质,编号 1∼n
其中,有 m对物质之间会发生反应。
现在,要将这些化学物质逐个倒入同一个试管之中,具体倒入顺序不限。
我们需要计算一下试管的危险值。
已知,空试管的危险值为 1,每倒入一种化学物质,如果该物质能够与之前倒入试管中的一种或多种物质发生反应,则试管的危险值将乘以 2
请你计算并输出,通过合理安排所有化学物质的倒入顺序,能够得到的试管的最大危险值。 -
思路
思路:找所有的连通块,每个连通块的祖先节点放入试管时,试管是不乘2的,其余情况都乘2
-
代码
/* * @Author: NEFU AB-IN * @Date: 2023-02-02 18:39:23 * @FilePath: \Acwing\85cp\b\b.cpp * @LastEditTime: 2023-02-02 19:09:55 */ #include <bits/stdc++.h> using namespace std; #define int long long #undef int #define SZ(X) ((int)(X).size()) #define ALL(X) (X).begin(), (X).end() #define IOS \ ios::sync_with_stdio(false); \ cin.tie(nullptr); \ cout.tie(nullptr) #define DEBUG(X) cout << #X << ": " << X << '\n' typedef pair<int, int> PII; const int N = 1e5 + 10, INF = 0x3f3f3f3f; string s; int k, mx; unordered_map<char, int> mp; signed main() { IOS; cin >> s >> k; for (char i = 'a'; i <= 'z'; ++i) { int x; cin >> x; mp[i] = x; mx = max(mx, x); } int ans = 0; for (int i = 0; i < SZ(s); ++i) { ans += (i + 1) * mp[s[i]]; } // DEBUG(ans); for (int i = SZ(s) + 1; i < SZ(s) + 1 + k; ++i) { ans += i * mx; } cout << ans; return 0; }
-

文章介绍了三道Acwing编程竞赛中的题目,包括死或生、最大价值和危险程度。对于死或生问题,通过比较两种状态的计数来决定结果。最大价值题解是通过贪心策略将最高价值的字母放在字符串末尾以最大化总价值。危险程度问题解决方法是找出所有不产生反应的物质序列以最大化试管的危险值。
839

被折叠的 条评论
为什么被折叠?



