比赛链接:kick start Round A 2020

A. Allocation

题目链接

题意

给出 \(N\) 栋房子的价格,第 \(i\) 栋房子的价格为 \(A_i\),你有 \(B\) 美元,问最多可以买多少栋房子?

思路

典型的贪心问题,将所有的房子按价格从低到高排序后选取即可。

代码

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int N = 1e5 + 10;
int _, Case;
void solve() {
Case++;
int n, b;
cin >> n >> b;
int a[n];
for (int i = 0; i < n; ++i) cin >> a[i];
sort(a, a + n);
int ans = 0;
for (int i = 0; i < n; ++i) {
if (b < a[i])
break;
else
b -= a[i], ans++;
}
cout << "Case #" << Case << ": " << ans << endl;
}
int main() {
// freopen("in.txt", "r", stdin);
ios::sync_with_stdio(false), cin.tie(0), cout.tie(0);
cin >> _;
while (_--) solve();
}

B. Plates

题目链接

题意

有 \(N\) 叠盘子,每叠有 \(K\) 个盘子,每个盘子有个 beauty value,现在要拿 \(P\) 个盘子,使得 beauty value 之和最大。拿盘子的条件:如果一个盘子的上面的盘子都被拿走了,才能拿到这个盘子。

思路

本题有一点点像多重背包。首先计算每叠盘子各自的前缀和 \(sum[N][K]\),设 \(dp[i][j]\) 表示前 \(i\) 堆盘子中取 \(j\) 个盘子的 beauty value 的最大值,转移方程为:

\[dp[i][j]=max\{dp[i][j],dp[i−1][j−l]+sum[i][l]|\ for\ l ∈\ [0,min(j,k)]\}
\]

代码

#include <bits/stdc++.h>
#define ms(a, b) memset(a, b, sizeof(a))
using namespace std;
typedef long long ll;
const int N = 1510;
int _, Case = 0;
int n, p, k, x;
int sum[N][N], a[N][N], dp[N][N];
void solve() {
ms(sum, 0), ms(a, 0), ms(dp, 0);//初始化
cin >> n >> k >> p;
for (int i = 1; i <= n; ++i)
for (int j = 1; j <= k; ++j) cin >> a[i][j];
cout << "Case #" << ++Case << ": ";
for (int i = 1; i <= n; ++i)
for (int j = 1; j <= k; ++j) sum[i][j] = sum[i][j - 1] + a[i][j];
for (int i = 0; i <= k; ++i) dp[1][i] = sum[1][i];
for (int i = 2; i <= n; ++i)
for (int j = 1; j <= p; ++j) //这里不需要太大,到p就够了
for (int l = 0; l <= min(j, k); ++l)//接下来就是写状态转移方程了
dp[i][j] = max(dp[i][j], dp[i - 1][j - l] + sum[i][l]); cout << dp[n][p] << endl;
}
int main() {
// freopen("in.txt", "r", stdin);
ios::sync_with_stdio(false), cin.tie(0), cout.tie(0);
for (cin >> _; _; _--) solve();
}

C. Workout

题目链接

题意

给定 \(N\) 个严格递增的数,往这 \(N\) 个数中间插 \(K\) 个数,插入后要使所有的数仍然保持严格递增,而且要保证相邻两数的最大绝对值之差最小,求最小的绝对值之差。

思路

想了挺久的,最后二分过的,典型的最大值最小的问题。判断函数的思路:传入参数 \(x\),表示答案为 \(x\),然后遍历每个数 \(num[i]\),如果 \(num[i+1]−num[i]>x\),就插入 \(num[i]+x\),如果插入的数的个数大于 \(K\) 个就返回 false,否则返回 true。

代码

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int inf = 0x3f3f3f3f;
const int N = 1e5 + 10;
int _, Case;
int n, k;
ll tmp[N], a[N];
bool check(int x) {
int cnt = 0;
for (int i = 0; i < n - 1; ++i)
while (tmp[i + 1] - tmp[i] > x) tmp[i] += x, cnt++;
if (cnt > k) return false;
return true;
}
void solve() {
cin >> n >> k;
for (int i = 0; i < n; ++i) cin >> a[i];
cout << "Case #" << ++Case << ": ";
int l = 1, r = inf;
while (l < r) {
int mid = (l + r) >> 1;
for (int i = 0; i < n; ++i) tmp[i] = a[i];
if (check(mid))
r = mid;
else
l = mid + 1;
}
cout << r << endl;
}
int main() {
// freopen("in.txt", "r", stdin);
ios::sync_with_stdio(false), cin.tie(0), cout.tie(0);
for (cin >> _; _; _--) solve();
}

D. Bundling

题目链接

题意

给定 \(N\) 个字符串,把它们分组,每组 \(K\) 个。每组的分数是该组所有字符串的最长公共前缀。求最大的所有组的分数和。

思路

很容易想到前缀树 (字典树 / trie 树,相关算法讲解),建完树后从根节点 dfs,同时记录深度 d,然后从叶子节点回溯,统计每个节点出现的个数 cnt,如果某个节点 \(u\) 的 \(cnt[u]≥K\),那么说明有 K 个字符串的前缀是以该节点结尾,深度 d 表示它们的前缀的长度,由于是从叶子节点回溯的,所以一定是最长公共前缀,所以 \(ans=ans+d\),同时 \(cnt[u]\) 减去 \(k\),即这 \(k\) 个字符串已经分完组,不再分到其他组。

代码

#include <bits/stdc++.h>
#define ms(a, b) memset(a, b, sizeof a)
using namespace std;
typedef long long ll;
const int inf = 0x3f3f3f3f;
const int N = 1e5 + 10; int trie[N << 2][30], tot = 1;
int cnt[N << 2], n, k, _, Case;
ll ans;
string s; void init() { ms(trie, 0), ms(cnt, 0), tot = 1, ans = 0; }
void insert(string s) {
int p = 0;
for (auto c : s) {
int idx = c - 'A';
if (!trie[p][idx]) trie[p][idx] = tot++;
p = trie[p][idx];
}
++cnt[p];
}
void dfs(int u, int d) { //起点,深度
for (int v = 0; v < 26; ++v) {
if (trie[u][v]) {
dfs(trie[u][v], d + 1);
cnt[u] += cnt[trie[u][v]];
}
}
ans += cnt[u] / k * d, cnt[u] %= k;
}
void solve() {
init();
cout << "Case #" << ++Case << ": ";
cin >> n >> k;
for (int i = 0; i < n; ++i) cin >> s, insert(s);
dfs(0, 0);
cout << ans << endl;
}
int main() {
// freopen("in.txt", "r", stdin);
ios::sync_with_stdio(false), cin.tie(0), cout.tie(0);
for (cin >> _; _; _--) solve();
}

这是第一次做Google平台的比赛,感觉难易度适中(适合我这种蒟蒻,感觉以后可以多写写)

Goolge Kick Start Round A 2020 (A ~ D题题解)的更多相关文章

  1. Codeforces Round #612 (Div. 2) 前四题题解

    这场比赛的出题人挺有意思,全部magic成了青色. 还有题目中的图片特别有趣. 晚上没打,开virtual contest打的,就会前三道,我太菜了. 最后看着题解补了第四道. 比赛传送门 A. An ...

  2. Codeforces Round #579 (Div. 3) 套题 题解

    A. Circle of Students      题目:https://codeforces.com/contest/1203/problem/A 题意:一堆人坐成一个环,问能否按逆时针或者顺时针 ...

  3. Codeforces Round #573 (Div. 2) D题题解

    一.题目 ​ Tokitsukaze, CSL and Stone Game ​ Tokitsukaze和CSL正在玩一些石头游戏. ​ 一开始,有n堆的石头,第i堆石头数记为 \(a_i\),两人轮 ...

  4. Codeforces Round #744 (Div. 3) G题题解

    淦,最后一道题没写出来,...还是我太菜了,不过这个题确实比较有趣. G. Minimal Coverage 简化题意:就是你处在坐标轴的0点上,给你一个序列\(a_i\),每次你可以选择向左走\(a ...

  5. Codeforces Round #741 (Div. 2)部分题题解

    我果然还是太菜了,就写了两道题....真是水死了.... A The Miracle and the Sleeper 简化题意:给定\(l,r\),求\(a\)%\(b\)的最大值,其中\(r> ...

  6. Google Kick Start Round G 2019

    Google Kick Start Round G 2019 Book Reading 暴力,没啥好说的 #include<bits/stdc++.h> using namespace s ...

  7. Codeforces Round #378 (Div. 2) D题(data structure)解题报告

    题目地址 先简单的总结一下这次CF,前两道题非常的水,可是第一题又是因为自己想的不够周到而被Hack了一次(或许也应该感谢这个hack我的人,使我没有最后在赛后测试中WA).做到C题时看到题目情况非常 ...

  8. Educational Codeforces Round 63 (Rated for Div. 2) 题解

    Educational Codeforces Round 63 (Rated for Div. 2)题解 题目链接 A. Reverse a Substring 给出一个字符串,现在可以对这个字符串进 ...

  9. Educational Codeforces Round 65 (Rated for Div. 2)题解

    Educational Codeforces Round 65 (Rated for Div. 2)题解 题目链接 A. Telephone Number 水题,代码如下: Code #include ...

  10. Educational Codeforces Round 64 (Rated for Div. 2)题解

    Educational Codeforces Round 64 (Rated for Div. 2)题解 题目链接 A. Inscribed Figures 水题,但是坑了很多人.需要注意以下就是正方 ...

随机推荐

  1. C# 泛型编译特性对性能的影响

    C#作为一种强类型语言,具有丰富的泛型支持,允许开发者编写可以应对不同数据类型的通用代码.然而,在泛型编译时,针对结构和类作为泛型参数时,会对性能产生不同的影响. 泛型编译行为 在C#中,泛型编译行为 ...

  2. 一行代码解决IE停用后无法继续使用IE弹窗功能的问题

    微软在2023年2月14日通过Edge浏览器更新,彻底封死IE.Windows Update中没有记录.开始菜单中的IE以及桌面IE图标双击自动打开Edge,默认程序设置了IE也没有任何效果,仅能通过 ...

  3. git 同时推送多个远程仓库

    今天遇到个git的问题:需要同时提交到两个远程仓库 解决方法: git add . git commit -m '提交信息' git remote -v git remote add old_orig ...

  4. 【工具推荐】LICEcap –GIF 屏幕录制工具

    介绍: LICEcap 是一款简洁易用的动画屏幕录制软件,支持导出 GIF 动画图片格式,轻量级.高质量(每帧颜色数量可超过256).使用简单,录制过程中可以随意改变录屏范围. LICEcap 非常轻 ...

  5. Win10操作系统安装Python

    1 Python解释器下载 1.1 安装环境 Windows 10 专业工作站版22H2 python-3.9.6-amd64.exe 1.2 下载地址 Python官网:https://www.py ...

  6. SpringCore完整学习教程4,入门级别

    本章从第4章开始 4. Logging Spring Boot使用Commons Logging进行所有内部日志记录,但保留底层日志实现开放.为Java Util Logging.Log4J2和Log ...

  7. [ABC263A] Full House

    Problem Statement We have five cards with integers $A$, $B$, $C$, $D$, and $E$ written on them, one ...

  8. 解决win10的wifi打不开或无法搜索到周围wifi的问题

    今天笔者遇到了一个比较奇葩的问题,就是笔记本电脑的wifi打不开了,即使打开了也是搜索不到周围的wifi的.这个问题一开始笔者没有发现,因为在暑假期间都是使用笔记本连接自己的手机热点进行上网的.然而暑 ...

  9. Cloudeye对接Prometheus实现华为云全方位监控

    本文分享自华为云社区<Cloudeye对接Prometheus实现华为云全方位监控>,作者:可以交个朋友 . 一. 背景 云眼系统Cloudeye服务为我们提供了针对弹性云服务器.宽带等资 ...

  10. 数字孪生技术与VR技术的结合会为我们带来什么?

    数字孪生技术与虚拟现实(VR)技术的结合为我们打开了全新的可能性和机遇.这个强大的联合为各个领域带来了巨大的影响和创新. 首先,数字孪生技术与VR技术的结合可以为设计和规划过程提供更直观.身临其境的体 ...