比赛链接: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. 使用C#将几个Excel文件合并去重分类

    需要将几个Excel表格里面的数据去重,然后将每个站点的数据另存为一张Sheet上. 几个表格如下所示: 实现效果如下所示: 具体实现 需要使用EPPlus操作Excel 安装EPPlus如下所示: ...

  2. 【Javaweb】Servlet六 | HttpServletRequest类的含义及其使用方法【详解】

    HttpServletRequest类的作用 每次只要有请求进入Tomcat服务器,Tomcat服务器就会把请求过来的Http协议信息解析好封装到Request对象中.然后传递到Service方法(d ...

  3. 通过滴滴技术博客:探寻造成此次P0故障的真正原因

    2023年11月27日晚至2023年11月28日早晨,滴滴发生了长达12小时的P0级故障,导致滴滴核心业务都受到了影响,比如不显示定位无法打车.滴滴单车无法扫码等问题,期间滴滴进行了多次致歉 目前问题 ...

  4. DevOps|研发提效-敏捷开发之每日站立会

    对于研发效能团队建设和组织,本文不再赘述,可以参考之前的文章,已经讲得很透彻了.本文重点讲我们日常是怎么开站立会,怎么让团队跑起来,高效能产出的.每日站立会,15分钟到30分钟,看似非常短的一个会,但 ...

  5. [ICPC2014WF]Sensor Network

    题目描述 A wireless sensor network consists of autonomous sensors scattered in an environment where they ...

  6. [CF1748E] Yet Another Array Counting Problem

    题目描述 The position of the leftmost maximum on the segment $ [l; r] $ of array $ x = [x_1, x_2, \ldots ...

  7. CISC与RISC

  8. 低代码之光!轻量级 GUI 的设计与实现

    前言 每当提起低代码,很多人都会下意识的出现过激反应,吐槽低代码都是**,唯恐避之不及.可能大部分人觉得低代码就是替代手写代码,对于程序员来说这是不可接受的.其实低代码表述的含义非常宽泛,我相信很多人 ...

  9. Pikachu漏洞靶场 Unsafe Filedownload(不安全的文件下载)

    不安全的文件下载 概述 文件下载功能在很多web系统上都会出现,一般我们当点击下载链接,便会向后台发送一个下载请求,一般这个请求会包含一个需要下载的文件名称,后台在收到请求后会开始执行下载代码,将该文 ...

  10. springMVC的基本介绍与入门

    1:MVC是什么? MVC是模型(Model).视图(View).控制器(Controller)的简写,是一种软件设计规范. Model(模型):数据模型,提高要展示的数据 现在一般是分为Value ...