比赛链接:Here

AB水题,

C - Many Balls

题意:

  • 现在有一个数初始为 \(0(x)\) 以及两种操作

    1. 操作 \(A:\) \(x + 1\)
    2. 操作 \(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 个人题解的更多相关文章

  1. KYOCERA Programming Contest 2021(AtCoder Beginner Contest 200) 题解

    KYOCERA Programming Contest 2021(AtCoder Beginner Contest 200) 题解 哦淦我已经菜到被ABC吊打了. A - Century 首先把当前年 ...

  2. AtCoder Beginner Contest 089完整题解

    A - Grouping 2 Time limit : 2sec / Memory limit : 256MB Score : 100 points Problem Statement There a ...

  3. 2018.09.08 AtCoder Beginner Contest 109简要题解

    比赛传送门 水题大赛? 全是水题啊!!! T1 ABC333 就是判断是不是两个数都是奇数就行了. 代码: #include<bits/stdc++.h> using namespace ...

  4. Atcoder Beginner Contest 138 简要题解

    D - Ki 题意:给一棵有根树,节点1为根,有$Q$次操作,每次操作将一个节点及其子树的所有节点的权值加上一个值,问最后每个节点的权值. 思路:dfs序再差分一下就行了. #include < ...

  5. AtCoder Beginner Contest 154 题解

    人生第一场 AtCoder,纪念一下 话说年后的 AtCoder 比赛怎么这么少啊(大雾 AtCoder Beginner Contest 154 题解 A - Remaining Balls We ...

  6. AtCoder Beginner Contest 153 题解

    目录 AtCoder Beginner Contest 153 题解 A - Serval vs Monster 题意 做法 程序 B - Common Raccoon vs Monster 题意 做 ...

  7. AtCoder Beginner Contest 177 题解

    AtCoder Beginner Contest 177 题解 目录 AtCoder Beginner Contest 177 题解 A - Don't be late B - Substring C ...

  8. AtCoder Beginner Contest 184 题解

    AtCoder Beginner Contest 184 题解 目录 AtCoder Beginner Contest 184 题解 A - Determinant B - Quizzes C - S ...

  9. AtCoder Beginner Contest 173 题解

    AtCoder Beginner Contest 173 题解 目录 AtCoder Beginner Contest 173 题解 A - Payment B - Judge Status Summ ...

  10. AtCoder Beginner Contest 172 题解

    AtCoder Beginner Contest 172 题解 目录 AtCoder Beginner Contest 172 题解 A - Calc B - Minor Change C - Tsu ...

随机推荐

  1. 手撕Vue-Router-添加全局$router属性

    前言 经过上一篇文章的介绍,完成了初始化路由相关信息的内容,接下来我们需要将路由信息挂载到Vue实例上,这样我们就可以在Vue实例中使用路由信息了. 简而言之就是给每一个Vue实例添加一个$route ...

  2. 有什么BI工具可以实现中国式报表?

    BI(Business Intelligence)工具是指用于帮助企业收集.分析.处理和展示数据的软件工具,以支持企业决策制定和业务运营优化的技术系统. 中国式报表在BI工具中的实现主要涉及到对中国商 ...

  3. [JDK/APM] 应用诊断工具之VisualVM

    1 概述 1.1 简介 VisualVM is a visual tool integrating commandline JDK tools and lightweight profiling ca ...

  4. org.springframework.context.ApplicationContextException: Failed to start bean 'documentationPluginsBootstrapper'; nested exception is java.lang.NullPointerException报错问题

    这个原因是 高版本SpringBoot整合swagger 造成的 我的项目是2.7.8 swagger版本是3.0.0 就会出现上面的报错 解决方式: 1.配置WebMvcConfigurer.jav ...

  5. 解决Tensorflow2.0出现:AttributeError: module 'tensorflow' has no attribute 'get_default_graph'的问题

    问题描述 在使用tensorflow2.0时,遇到了这个问题: AttributeError: module 'tensorflow' has no attribute 'get_default_gr ...

  6. python操作mongodb副本集(mongodb高可用)

    https://pymongo.readthedocs.io/en/stable/examples/high_availability.html# pymongo比较"智能",只要 ...

  7. scrapy 请求meta参数使用案例-豆瓣电影爬取

    num = 0 import scrapy from scrapy.http import HtmlResponse from scrapy_demo.items import DoubanItem ...

  8. MySQL 数据目录

    MySQL 的数据目录 1. MySQL 的主要目录结构 方式1:通过命令搜索 find / -name mysql 方式2(推荐):通过查看配置文件获取目录结构 vim /etc/my.cnf (重 ...

  9. mv 用法

    ls #查看目录下所有文件 mkdir 11 #创建11文件夹 mv * 11/ #把所有文件移动到11文件夹下 cd 11 #进入11文件夹 ls #查看文件夹里的内容 mv * ../ #把11文 ...

  10. [西湖论剑2023-Misc] 复现

    MISC mp3 题目 我的解答: 010发现mp3藏有png图片 卡里分离得到图片 foremost cipher.mp3 zsteg发现里面有压缩包 提取出来 zsteg -e b1,r,lsb, ...