【解题报告】Educational Codeforces Round 9
来源:互联网 发布:蚁群算法优化问题 编辑:程序博客网 时间:2024/05/15 23:50
题目链接
A.Grandma Laura and Apples(Codeforces 632A)
大意
奶奶有若干个苹果,当她还剩奇数个苹果的时候会卖出一半的苹果(比如奶奶还剩
思路
不妨先顺着问题发生的顺序理一理思路。假设奶奶有
代码
#include <bits/stdc++.h>using namespace std;char s[10];int n, p, a[50];long long m, ans;int main() { scanf("%d%d", &n, &p); for(int i = 0; i < n; i++) { scanf("%s", s); if(strlen(s) > 4) a[i] = 1; else a[i] = 0; } for(int i = n - 1; i >= 0; i--) { if(a[i]) m = (m + 5) << 1; else m <<= 1; ans += m / 2; } printf("%I64d\n", ans * p / 10); return 0;}
B. Alice, Bob, Two Teams(Codeforces 632B)
大意
有一个只含
思路
既然
代码
#include <bits/stdc++.h>using namespace std;const int maxn = 5e5 + 10;char s[maxn];int n, p[maxn];long long sum, tmp, ans;int main() { scanf("%d", &n); for(int i = 0; i < n; i++) { scanf("%d", &p[i]); } scanf("%s", s); sum = 0; for(int i = 0; i < n; i++) { if(s[i] == 'B') { sum += p[i]; } } ans = tmp = sum; for(int i = 0; i < n; i++) { if(s[i] == 'A') { tmp += p[i]; ans = max(ans, tmp); } else tmp -= p[i]; } tmp = sum; for(int i = n - 1; i >= 0; i--) { if(s[i] == 'A') { tmp += p[i]; ans = max(ans, tmp); } else tmp -= p[i]; } printf("%I64d\n", ans); return 0;}
C.The Smallest String Concatenation(Codeforces 632C)
大意
有一个字符串集合,问将集合中的字符串首尾相连能够得到的字典序最小的字符串是什么。
思路
刚拿到这道题的时候,感觉应该是按照字典序排序,然后直接按照排序结果首尾相连。但是后来验证猜想的时候就出问题了。例如,有三个字符串:
代码
#include <bits/stdc++.h>using namespace std;const int maxn = 5e4 + 5;int n;string ans, s[maxn];bool cmp(string a, string b) { return a + b < b + a;}int main() { ios::sync_with_stdio(false); cin >> n; for(int i = 0; i < n; i++) { cin >> s[i]; } sort(s, s + n, cmp); ans = ""; for(int i = 0; i < n; i++) { ans = ans + s[i]; } cout << ans << endl; return 0;}
D. Longest Subsequence(Codeforces 632D)
大意
有一个含
思路
看见题中有
代码
#include <bits/stdc++.h>using namespace std;const int maxn = 1e6 + 5;int n, m, l, a[maxn], d[maxn];int main() { scanf("%d%d", &n, &m); for(int i = 1; i <= n; i++) { scanf("%d", &a[i]); // 输入的同时维护d数组 if(a[i] <= m) d[a[i]]++; } // 逆序遍历d数组 for(int i = m; i >= 1; i--) { // 枚举i的倍数 for(int j = 2 * i; j <= m; j += i) { d[j] += d[i]; } } l = max_element(d + 1, d + m + 1) - d; printf("%d %d\n", l, d[l]); for(int i = 1; i <= n; i++) { if(l % a[i] == 0) { printf("%d ", i); } } puts(""); return 0;}
(其它题目略)
- 【解题报告】Educational Codeforces Round 9
- Educational Codeforces Round 6 解题报告
- 【解题报告】Educational Codeforces Round 12
- 【解题报告】Educational Codeforces Round 13
- 【解题报告】Educational Codeforces Round 15
- 【解题报告】Educational Codeforces Round 16
- 【解题报告】Educational Codeforces Round 14
- 【解题报告】 Educational Codeforces Round 19
- 【解题报告】Educational Codeforces Round 20
- [Updating] Educational Codeforces Round 20 解题报告
- 【解题报告】Educational Codeforces Round 21
- 解题报告: Educational Codeforces Round 24 A,B,C
- 解题报告:Educational Codeforces Round 24 D,E,F
- Educational Codeforces Round 9
- Educational Codeforces Round 9
- Educational Codeforces Round 9
- Educational Codeforces Round 9
- Codeforces Educational Round 34划水报告
- 数字在排序数组中出现的次数
- 布局之merge的使用
- mysql 高可用集群实验性搭建
- Java finally语句到底是在return之前还是之后执行?
- web开发与IC卡读卡器
- 【解题报告】Educational Codeforces Round 9
- linux下文件同步脚本
- 针对android&ios yuv旋转、镜像、格式转换、裁剪 算法实现
- 在Ubuntu 配置图标程序
- 如何使QLineEdit禁止编辑
- Android支付接入(七):Google In-app-Billing
- 安卓学习之-Fragment-1
- [【Linux命令003】ln建立软链接
- 【Android学习系列】AndroidManifest.xml文件详解(data)