AtCoder Beginner Contest 362
AtCoder Beginner Contest 362
前言
vp 的时候出了四题,被 C 题卡了一会,很久才出,D 题是 dijkstra 的板子,改下条件即可,E 题是个计数 dp,这类题一直不怎么擅长,想起之前杭电第一场那个序列立方的题也是类似这种计数 dp,需要加强练习。
A - Buy a Pen (atcoder.jp)
思路
判断两两最小。
代码
#include <bits/stdc++.h>
using namespace std;
using i64 = long long;
int main() {
ios::sync_with_stdio(false);
cin.tie(nullptr);
int a, b, c;
cin >> a >> b >> c;
string x;
cin >> x;
if (x == "Red") cout << min(b, c) << '\n';
if (x == "Blue") cout << min(a, b) << '\n';
if (x == "Green") cout << min(a, c) << '\n';
return 0;
}
B - Right Triangle (atcoder.jp)
思路
根据勾股定理判一下即可,这里坐标都很小,可以不用开方,开方的话还会涉及到精度问题。
代码
#include <bits/stdc++.h>
using namespace std;
using i64 = long long;
struct point {
i64 x;
i64 y;
} ;
//求两点之间的距离
i64 dis(point p1, point p2) {
return ((p1.x - p2.x) * (p1.x - p2.x) + (p1.y - p2.y) * (p1.y - p2.y));
}
int main() {
ios::sync_with_stdio(false);
cin.tie(nullptr);
point a, b, c;
cin >> a.x >> a.y >> b.x >> b.y >> c.x >> c.y;
i64 ab = dis(a, b);
i64 ac = dis(a, c);
i64 bc = dis(b, c);
if ((ab + ac == bc) || (ab + bc == ac) || (ac + bc == ab)) {
printf("Yes");
}
else {
printf("No");
}
return 0;
}
C - Sum = 0 (atcoder.jp)
思路
先累计两边边界的和,记为 \(sum_l\) 和 \(sum_r\) ,如果 \(sum_l>0\) 说明左边取全最小都还是不可能等于 0 ,右边同理,这种特殊处理一下即可。
考虑当 \(sum_l\le 0\) 的时候,那我们只要往右边偏移 \(|sum_l|\) 即可,把小于 0 的那部分用正数来补;右边同理。
代码
#include <bits/stdc++.h>
using namespace std;
using i64 = long long;
int main() {
ios::sync_with_stdio(false);
cin.tie(nullptr);
int n;
cin >> n;
i64 lsum = 0, rsum = 0;
vector<array<i64, 2>> node(n);
for (auto &[x, y] : node) {
cin >> x >> y;
lsum += x, rsum += y;
}
if (lsum > 0 || rsum < 0) {
cout << "No\n";
return 0;
}
cout << "Yes\n";
if (lsum <= 0) {
i64 now = -lsum;
for (auto [x, y] : node) {
if (now) {
cout << min(x + now, y) << ' ';
now -= min(x + now, y) - x;
} else
cout << x << ' ';
}
} else {
i64 now = rsum;
for (auto [x, y] : node) {
if (now) {
cout << max(x, y - now) << ' ';
now -= y - max(y - now, x);
} else
cout << y << ' ';
}
}
return 0;
}
D - Shortest Path 3 (atcoder.jp)
思路
dijkstra 板子题,只要在判断条件那里增加一个 \(a_v\) 即可。
代码
#include <bits/stdc++.h>
using namespace std;
using i64 = long long;
int main() {
ios::sync_with_stdio(false);
cin.tie(nullptr);
int n, m;
cin >> n >> m;
vector<int> a(n + 1);
for (int i = 1; i <= n; i ++)
cin >> a[i];
vector g(n + 1, vector<array<int, 2>>());
for (int i = 0; i < m; i ++) {
int u, v, w;
cin >> u >> v >> w;
g[u].push_back({v, w});
g[v].push_back({u, w});
}
vector<i64> dis(n + 1, LLONG_MAX >> 1);
priority_queue<pair<i64, i64>, vector<pair<i64, i64>>, greater<>> Q;
dis[1] = a[1];
Q.push({dis[1], 1});
while (Q.size()) {
auto [_, u] = Q.top();
Q.pop();
if (dis[u] < _) continue;
for (auto [v, w] : g[u]) {
if (dis[v] > dis[u] + w + a[v]) {
dis[v] = dis[u] + w + a[v];
Q.push({dis[v], v});
}
}
}
for (int i = 2; i <= n; i ++)
cout << dis[i] << " \n"[i == n];
return 0;
}
E - Count Arithmetic Subsequences (atcoder.jp)
思路
考虑计数 dp。
设 \(dp_{i,j,k}\) 为长度为 i 的子序列末尾两项为 \(a_j\) 和 \(a_k\) 的方案数。
转移的时候可以枚举倒数第三项来转移:
\]
代码
// LUOGU_RID: 169183095
#include <bits/stdc++.h>
using namespace std;
using i64 = long long;
constexpr i64 mod = 998244353, N = 300;
i64 dp[N][N][N] {};
int main() {
ios::sync_with_stdio(false);
cin.tie(nullptr);
int n;
cin >> n;
vector<int> a(n + 1);
for (int i = 1; i <= n; i ++)
cin >> a[i];
if (n == 1) {
cout << 1 << '\n';
return 0;
}
vector<int> ans(n + 1);
ans[1] = n, ans[2] = n * (n - 1) / 2;
for (int i = 1; i <= n; i ++) {
for (int j = i + 1; j <= n; j ++) {
dp[2][i][j] = 1;
}
}
for (int len = 3; len <= n; len ++) {
for (int j = len - 1; j <= n; j ++) {
for (int k = j + 1; k <= n; k ++) {
for (int i = len - 2; i < j; i ++) {
if (a[j] - a[i] == a[k] - a[j]) {
(dp[len][j][k] += dp[len - 1][i][j]) %= mod;
}
}
(ans[len] += dp[len][j][k]) %= mod;
}
}
}
for (int i = 1; i <= n; i ++)
cout << ans[i] << " \n"[i == n];
return 0;
}
AtCoder Beginner Contest 362的更多相关文章
- AtCoder Beginner Contest 100 2018/06/16
A - Happy Birthday! Time limit : 2sec / Memory limit : 1000MB Score: 100 points Problem Statement E8 ...
- AtCoder Beginner Contest 052
没看到Beginner,然后就做啊做,发现A,B太简单了...然后想想做完算了..没想到C卡了一下,然后还是做出来了.D的话瞎想了一下,然后感觉也没问题.假装all kill.2333 AtCoder ...
- AtCoder Beginner Contest 053 ABCD题
A - ABC/ARC Time limit : 2sec / Memory limit : 256MB Score : 100 points Problem Statement Smeke has ...
- AtCoder Beginner Contest 136
AtCoder Beginner Contest 136 题目链接 A - +-x 直接取\(max\)即可. Code #include <bits/stdc++.h> using na ...
- AtCoder Beginner Contest 137 F
AtCoder Beginner Contest 137 F 数论鬼题(虽然不算特别数论) 希望你在浏览这篇题解前已经知道了费马小定理 利用用费马小定理构造函数\(g(x)=(x-i)^{P-1}\) ...
- AtCoder Beginner Contest 076
A - Rating Goal Time limit : 2sec / Memory limit : 256MB Score : 100 points Problem Statement Takaha ...
- AtCoder Beginner Contest 079 D - Wall【Warshall Floyd algorithm】
AtCoder Beginner Contest 079 D - Wall Warshall Floyd 最短路....先枚举 k #include<iostream> #include& ...
- AtCoder Beginner Contest 064 D - Insertion
AtCoder Beginner Contest 064 D - Insertion Problem Statement You are given a string S of length N co ...
- AtCoder Beginner Contest 075 D - Axis-Parallel Rectangle【暴力】
AtCoder Beginner Contest 075 D - Axis-Parallel Rectangle 我要崩溃,当时还以为是需要什么离散化的,原来是暴力,特么五层循环....我自己写怎么都 ...
- AtCoder Beginner Contest 075 C bridge【图论求桥】
AtCoder Beginner Contest 075 C bridge 桥就是指图中这样的边,删除它以后整个图不连通.本题就是求桥个数的裸题. dfn[u]指在dfs中搜索到u节点的次序值,low ...
随机推荐
- MapInfo 12.0 及 mapbasic 12.0 安装过程当中遇到的问题的汇总
目录 MapInfo 12.0 及 mapbasic 12.0 安装过程当中遇到的问题的汇总 C++ 运行时库 Unable to load the CLR (-2147467263) 1) .NET ...
- nginx 信号量
nginx支持的信号量 TERM, INT fast shutdown QUIT graceful shutdown HUP changing configuration, keeping up wi ...
- Kubernetes(三)实战入门
实战入门 本章介绍如何在kubernetes集群中部署一个nginx服务,并能够对其进行访问. 1. Namespace Namespace主要作用是实现多套环境的资源隔离或者多租户的资源隔离. 默认 ...
- Spark Structured Streaming(一)基础
1. 流处理的场景 我们在定义流处理时,会认为它处理的是对无止境的数据集的增量处理.不过对于这个定义来说,很难去与一些实际场景关联起来.在我们讨论流处理的优点与缺点时,先介绍一下流处理的常用场景. 通 ...
- 基于 TI Sitara系列 AM64x核心板——程序自启动说明
前 言 本文主要介绍AM64x的Cortex-A53.Cortex-M4F和Cortex-R5F核心程序自启动使用说明.默认使用AM6442进行测试演示,AM6412测试步骤与之类似. 本说明文档适用 ...
- 学习.NET 8 MiniApis入门
介绍篇 什么是MiniApis? MiniApis的特点和优势 MiniApis的应用场景 环境搭建 系统要求 安装MiniApis 配置开发环境 基础概念 MiniApis架构概述 关键术语解释(如 ...
- InvocationTargetException和UndeclaredThrowableException异常介绍
今天来介绍了两个陌生又熟悉的异常类,熟悉是因为我们经常会遇到它们,陌生是好像又从来不知道它们是做什么的 假定读者已经清楚了Java的异常分类: 一是程序不能处理的错误(Error), 二是程序应该避免 ...
- Mac Eclipse 常用快捷键汇总
寻找类:shift+command+t 删除当前行:command+d 上移当前行代码:option+↑ 下移当前行代码:option+↓ 复制当前行至下一行:option+command+↓ 复制当 ...
- 图的存储、创建、遍历、求最小生成树、最短路径(Java)
带权无向图 存储结构 存储结构选用邻接表. 当一个图为稀疏图时,使用邻接矩阵法显然要浪费大量的存储空间,而图的邻接表法结合了顺序存储和链式存储方法,大大减少了这种不必要的浪费. 当然,即使我们所处理的 ...
- [oeasy]python0004_游乐场_和python一起玩耍_python解释器_数学运算
和python玩耍 Python 回忆 上次 了解shell环境中的命令 命令 作用 whoami 显示当前用户名 pwd 显示当前文件夹 ls 列出当前文件夹下的内容 python3 仿佛进入大于号 ...