当前位置: 首页 > news >正文

AtCoder Beginner Contest 421

文章目录

    • A Misdelivery
    • B Fibonacci Reversed
    • C Alternated
    • D RLE Moving
    • E Yacht
    • F Erase between X and Y
    • G Increase to make it Increasing

AtCoder Beginner Contest 421

A Misdelivery

Mansion AtCoder has N rooms numbered from room 1 to room N.
Each room i is inhabited by one person named Si.
You are to deliver a package addressed to Mr./Ms. Y in room X. Determine whether the destination is correct.

翻译:
AtCoder 公寓有 N 个房间,编号从 1 到 N。
每个房间 i 都住着一位名叫 Si 的人。
你需要将一个包裹送到 X 房间的 Y 先生/女士手中。请确认收件人地址是否正确。

分析:判断数组 a[x] 是否为 y。

#include <bits/stdc++.h>
using namespace std;void solve() {int n; cin >> n;vector<string> s;string x;for (int i = 1; i <= n; i++)cin >> x, s.push_back(x);int p; cin >> p >> x;cout << (s[p - 1] == x ? "Yes" : "No") << "\n";
}
int main() {int T = 1; while (T--) solve();return 0;
}

B Fibonacci Reversed

#include <bits/stdc++.h>
using ll = long long;
using namespace std;ll f(int a) {string s = to_string(a);reverse(s.begin(), s.end());return atoll(s.c_str());
}
void solve() {ll x, y; cin >> x >> y;vector<ll> a({0, x, y});for (int i = 3; i <= 10; i++)a.push_back(f(a[i - 1] + a[i - 2]));cout << a[10] << "\n";
}
signed main() {int T = 1; while (T--) solve();return 0;
}

C Alternated

#include <bits/stdc++.h>
using ll = long long;
using namespace std;
const int N = 1e6 + 5;
vector<int> a(N), tmp(N);
void msort(int l, int r, ll& cnt) {if (l >= r) return;int mid = l + r >> 1, i = l, j = mid + 1, p = 0;msort(l, mid, cnt), msort(mid + 1, r, cnt);while (i <= mid && j <= r) {if (a[i] <= a[j]) tmp[++p] = a[i++];else tmp[++p] = a[j++], cnt += mid - i + 1ll;}while (i <= mid) tmp[++p] = a[i++];while (j <= r) tmp[++p] = a[j++];for (int i = 1; i <= p; i++) a[l++] = tmp[i];
}
void solve() {int n; string s;cin >> n >> s, n *= 2;int x = 1, y = 2;for (int i = 0; i < n; i++) {if (s[i] == 'A') a[i + 1] = x, x += 2;else a[i + 1] = y, y += 2;}ll cnt1 = 0, cnt2 = 0;msort(1, n, cnt1);x = 2, y = 1;for (int i = 0; i < n; i++) {if (s[i] == 'A') a[i + 1] = x, x += 2;else a[i + 1] = y, y += 2;}msort(1, n, cnt2);cout << min(cnt1, cnt2) << "\n";
}
signed main() {int T = 1; while (T--) solve();return 0;
}

D RLE Moving

E Yacht

F Erase between X and Y

G Increase to make it Increasing

http://www.dtcms.com/a/359136.html

相关文章:

  • Mysql 学习day 2 深入理解Mysql索引底层数据结构
  • 【开题答辩全过程】以 基于WEB的茶文化科普系统的设计与实现为例,包含答辩的问题和答案
  • 用简单仿真链路产生 WiFi CSI(不依赖专用工具箱,matlab实现)
  • 面试tips--MyBatis--<where> where 1=1 的区别
  • 如何查看Linux系统中文件夹或文件的大小
  • 【LeetCode - 每日1题】有效的数独
  • SQLSugar 快速入门:从基础到实战查询与使用指南
  • MySQL 在 CentOS 上的安装与配置文件路径详解
  • 【系列06】端侧AI:构建与部署高效的本地化AI模型 第5章:模型剪枝(Pruning)
  • 【LeetCode - 每日1题】鲜花游戏
  • 深度学习:洞察发展趋势,展望未来蓝图
  • Verilog 硬件描述语言自学——重温数电之典型组合逻辑电路
  • 深度学习通用流程
  • 用更少的数据识别更多情绪:低资源语言中的语音情绪识别新方法
  • nestjs连接oracle
  • 大模型备案、算法备案补贴政策汇总【广东地区】
  • SNMPv3开发--snmptrapd
  • CNB远程部署和EdgeOne Pages
  • More Effective C++ 条款18:分期摊还预期的计算成本(Amortize the Cost of Expected Computations)
  • 数据库的CURD
  • Shell 秘典(卷三)——循环运转玄章 与 case 分脉断诀精要
  • C语言类型转换踩坑解决过程
  • Java高并发架构核心技术有哪些?
  • 安装Redis
  • compute:古老的计算之道
  • 【ROS2】ROS2 基础学习教程 、movelt学习
  • Docker实战避坑指南:从入门到精通
  • plantsimulation知识点 多条RGV驮一台工件图标显示顺序问题
  • lumerical_FDTD_光源_TFSF
  • 【AI】【强化学习】强化学习算法总结、资料汇总、个人理解