AtCoder Beginner Contest 216 个人题解
比赛链接:Here
AB水题,
C - Many Balls
题意:
现在有一个数初始为 \(0(x)\) 以及两种操作
- 操作 \(A:\) \(x + 1\)
- 操作 \(B: 2\times x\)
数据范围 \(n \le 1e18\)
现在给你一个数 \(n\) ,问如何通过以上操作将 \(0\) 变成 \(n\) ,操作数不超过 \(120\)
思路:
\(2^{119} \ge 1e18\) 保证一定有解
首先我们肯定是操作\(A\) 使得 \(x=1\) 不然执行操作 \(B\) 无意义
接下来尽可能使得 \(x\) 接近 \(n\) 也就是多执行操作\(B\)
接下来就是补 \(A\) 了
int main() {
cin.tie(nullptr)->sync_with_stdio(false);
ll n;
cin >> n;
stack<char>st;
while (n) {
while (n % 2 == 0) {
n /= 2;
st.push('B');
}
while (n % 2 != 0) {
n -= 1;
st.push('A');
}
}
while (!st.empty()) {
cout << st.top();
st.pop();
}
}
思路二:
用二进制的眼光看数字。对一个二进制数字来说要增加一个 \(0\) 就要乘 \(2\) ,增加一个 \(1\) 就要乘 \(2\) 加 \(1\) 。从高位到低位看数字 \(n\) ,第一个出现 \(1\) 的位置就是一开始的加 \(1\) ,然后剩下的位置中,如果是 \(1\) ,就一定是\(\times2+1\) 得到的,是 \(0\) 就是 \(\times 2\) 得到的。
【AC Code】
int a[120];
int main() {
cin.tie(nullptr)->sync_with_stdio(false);
ll n;
cin >> n;
int cnt = 0;
while (n) {
a[cnt ++] = n % 2;
n /= 2;
}
for (int i = cnt - 1; i >= 0; i -= 1) {
if (i == cnt - 1) {
cout << "A";
continue;
}
if (a[i] == 1)cout << "BA";
else cout << "B";
}
}
D - Pair of Balls
赛时懵逼了,一下子没想到用
map去处理
题意:
- 给 \(2N\) 个球,编号都在 \(1\) 到 \(N\) 的范围内,每个编号的球恰好有两个,放入 \(M\) 个容器中,每个容器大小为 \(K_i\) ,现在有一种操作:从某个容器顶部的球(前提是另外一个容器的顶部也是这个球的编号),然后把这两个球都去掉,重复操作下来,问能否把全部栈清空。
思路:
数组 \(mp_i\) 代表编号为 \(i\)的球在哪个容器中,对每一个容器 \(i\) 顶部依次搜索,如果另一个容器 \(j\) 顶部跟当前容器顶部相同就去掉,然后再对容器 \(j\) 搜索,具体看代码。
const int N = 2e5 + 10;
queue<int>q[N];
int mp[N];
void dfs(int i) {
int u = mp[q[i].front()];
q[u].pop();
q[i].pop();
while (!q[u].empty() and mp[q[u].front()]) dfs(u);
if (!q[u].empty()) mp[q[u].front()] = u;
}
int main() {
cin.tie(nullptr)->sync_with_stdio(false);
int n, m;
cin >> n >> m;
for (int i = 1, k; i <= m; ++i) {
cin >> k;
for (int j = 1, x; j <= k; ++j) {
cin >> x;
q[i].push(x);
}
}
for (int i = 1; i <= m; ++i) {
while (!q[i].empty() and mp[q[i].front()]) dfs(i);
if (!q[i].empty()) mp[q[i].front()] = i;
}
bool f = 0;
for (int i = 1; i <= m; ++i) {
if (!q[i].empty()) {f = 1; break;}
}
cout << (!f ? "Yes\n" : "No\n");
}
E - Amusement Park
题意:
\(RioTian\) 来到了一个游乐园,游乐园里有 \(N\) 个景点,并且第 \(i\) 个景点的乐趣最开始是 \(a_i\) 随着 \(RioTian\) 的游玩,他的满足感数值会增加当前游玩景点乐趣值,但每一次游玩该景点后此景点乐趣值 \(-1\) ,\(RioTian\) 最多可以以任何顺序乘坐景点K次。
请问 \(RioTian\) 能得到的最大可能的满意度是什么?
\(eg:\) 除了乘坐景点外,没有什么能影响 \(RioTian\) 的满意度。
思路:
感觉做过哎(雾)
为了使得满意度最大化,肯定是先游玩乐趣值大的那几个景点,并且判断是不是能重复游玩使得值最大化。
详细见代码
const int N = 2e5 + 10;
ll a[N];
int main() {
cin.tie(nullptr)->sync_with_stdio(false);
ll n, k;
cin >> n >> k;
for (int i = 1; i <= n; ++i) cin >> a[i];
sort(a + 1, a + 1 + n, greater<ll>());
ll ans = 0;
for (int i = 1; i <= n; ++i) {
ll t = i * (a[i] - a[i + 1]);
if (k >= t) k -= t, ans += (a[i] + a[i + 1] + 1) * t / 2;
else {
ll tt = k / i, j = k % i;
ans += (a[i] + a[i] - tt + 1) * tt / 2 * i + j * (a[i] - tt);
break;
}
}
cout << ans;
}
AtCoder Beginner Contest 216 个人题解的更多相关文章
- KYOCERA Programming Contest 2021(AtCoder Beginner Contest 200) 题解
KYOCERA Programming Contest 2021(AtCoder Beginner Contest 200) 题解 哦淦我已经菜到被ABC吊打了. A - Century 首先把当前年 ...
- AtCoder Beginner Contest 089完整题解
A - Grouping 2 Time limit : 2sec / Memory limit : 256MB Score : 100 points Problem Statement There a ...
- 2018.09.08 AtCoder Beginner Contest 109简要题解
比赛传送门 水题大赛? 全是水题啊!!! T1 ABC333 就是判断是不是两个数都是奇数就行了. 代码: #include<bits/stdc++.h> using namespace ...
- Atcoder Beginner Contest 138 简要题解
D - Ki 题意:给一棵有根树,节点1为根,有$Q$次操作,每次操作将一个节点及其子树的所有节点的权值加上一个值,问最后每个节点的权值. 思路:dfs序再差分一下就行了. #include < ...
- AtCoder Beginner Contest 154 题解
人生第一场 AtCoder,纪念一下 话说年后的 AtCoder 比赛怎么这么少啊(大雾 AtCoder Beginner Contest 154 题解 A - Remaining Balls We ...
- AtCoder Beginner Contest 153 题解
目录 AtCoder Beginner Contest 153 题解 A - Serval vs Monster 题意 做法 程序 B - Common Raccoon vs Monster 题意 做 ...
- AtCoder Beginner Contest 177 题解
AtCoder Beginner Contest 177 题解 目录 AtCoder Beginner Contest 177 题解 A - Don't be late B - Substring C ...
- AtCoder Beginner Contest 184 题解
AtCoder Beginner Contest 184 题解 目录 AtCoder Beginner Contest 184 题解 A - Determinant B - Quizzes C - S ...
- AtCoder Beginner Contest 173 题解
AtCoder Beginner Contest 173 题解 目录 AtCoder Beginner Contest 173 题解 A - Payment B - Judge Status Summ ...
- AtCoder Beginner Contest 172 题解
AtCoder Beginner Contest 172 题解 目录 AtCoder Beginner Contest 172 题解 A - Calc B - Minor Change C - Tsu ...
随机推荐
- 大立科技DM63红外相机SDK开发Ⅰ-连接仪器
1.开发准备 为了方便发开,需要下载Visual Studio,本开发基于Visual Studio 2022,使用C++. 通过Visual Studio创建好项目后,将DMSDK V1.16.3内 ...
- MySQL - Plugin 'InnoDB' registration as a STORAGE ENGINE failed 错误处理
版权声明:原创作品,谢绝转载!否则将追究法律责任. ----- 作者:kirin Plugin 'InnoDB' registration as a STORAGE ENGINE failed,从详细 ...
- 数据库系列:MySQL InnoDB锁机制介绍
数据库系列:MySQL慢查询分析和性能优化 数据库系列:MySQL索引优化总结(综合版) 数据库系列:高并发下的数据字段变更 数据库系列:覆盖索引和规避回表 数据库系列:数据库高可用及无损扩容 数据库 ...
- 洛谷4159 [SCOI2009] 迷路(矩阵快速幂,拆点)
题意:该有向图有 n 个节点,节点从 1至 n 编号,windy 从节点 1 出发,他必须恰好在 t 时刻到达节点 n.现在给出该有向图,你能告诉 windy 总共有多少种不同的路径吗?答案对2009 ...
- NVIDIA RTX4090,你能用它做什么?
都说男生是世界上最简单的动物,为什么呢?举个例子,你要给女朋友送礼,你可以选择包.口红.护肤品.化妆品等,而包的品牌和样式.口红的色号等足以让你挑得眼花缭乱.而男生不一样,如果女生选择给男生送礼,我相 ...
- OkHttp3发送http请求
导入依赖 <!-- https://mvnrepository.com/artifact/com.squareup.okhttp3/okhttp --> <dependency> ...
- 华企盾DSC在苹果电脑上加密文件不显示加密图标
1.首先mac端暂时只支持在访达内显示加密图标,且新建的加密文件需要切换目录才可查看 2.检查DSCFinderSync进程是否启动,若没有启动重启一下DSC进程 3.若还没有显示直接重启系统的访达进 ...
- 在WInform开发中实现工具栏/菜单的动态呈现
在Winform系统开发中,为了对系统的工具栏/菜单进行动态的控制,我们对系统的工具栏/菜单进行动态配置,这样可以把系统的功能弹性发挥到极致.通过动态工具栏/菜单的配置方式,我们可以很容易的为系统新增 ...
- 面向对象(OOP)
面向对象 面向对象 面向过程 & 面向对象 面向过程思想 步骤清晰简单,第一步做什么,第二步做什么... 面对过程适合处理一些较为简单问题 面向对象思想 物以类聚,分类的思维模式,思考问题首先 ...
- mybatis空格字符替换
mybatis空格字符替换 <select id="user" resultType="java.util.Map" parameterType=&quo ...