AtCoder Beginner Contest 180 个人题解(快乐DP场)
补题链接:Here
A - box
输出
B - Various distances
按题意输出 3 种距离即可
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
int main() {
ios_base::sync_with_stdio(false), cin.tie(0);
int N;
ll x;
ll ans1 = 0, ans2 = 0, ans3 = 0;
cin >> N;
for (int i = 0; i < N; i++) {
cin >> x;
ans1 += abs(x);
ans2 += x * x;
ans3 = max(ans3, abs(x));
}
double ans2_ = sqrt(double(ans2));
cout << ans1 << endl;
cout << fixed << setprecision(20) << ans2_ << endl;
cout << ans3 << endl;
}
C - Cream puff
set
容器存因子,然后循环输出
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
int main() {
ios_base::sync_with_stdio(false), cin.tie(0);
ll x, y, a, b;
cin >> x >> y >> a >> b;
ll ans = 0;
while ((a - 1) * x <= b && a * x < y && (double)a * x <= 2e18) {
x *= a, ans++;
}
cout << ans + (y - 1 - x) / b << '\n';
return 0;
}
D - Takahashi Unevolved
题意:Iroha 在游戏中有一只宠物加 Takahashi,为了帮助 Takahashi 变得强力起来,需要将它送入训练场
- Kakomon Gym:
- AtCoder Gym:
但是 STR 不能超过 Y 的情况下求 EXP 的最大值
思路:最大化去第一种 Gym 的次数然后用 Y减去差值除 B 即可
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
int main() {
ios_base::sync_with_stdio(false), cin.tie(0);
ll x, y, a, b;
cin >> x >> y >> a >> b;
ll ans = 0;
while ((a - 1) * x <= b && a * x < y && (double)a * x <= 2e18) {
x *= a, ans++;
}
cout << ans + (y - 1 - x) / b << '\n';
return 0;
}
E - Traveling Salesman among Aerial Cities
https://blog.csdn.net/weixin_45750972/article/details/109144617
题意:给定边权的计算方法,求n nn个结点的最小曼哈顿回路花费。
思路:状压DP
令
最后答案即为:
状态方程:
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
const int N = 17, M = (1 << 17) + 1;
int n, x[N], y[N], z[N];
ll dp[M][N];
ll d(int a, int b) {
return abs(x[a] - x[b]) + abs(y[a] - y[b]) + max(0, z[b] - z[a]);
}
int main() {
ios_base::sync_with_stdio(false), cin.tie(0);
cin >> n;
for (int i = 0; i < n; ++i) cin >> x[i] >> y[i] >> z[i];
memset(dp, 0x3f, sizeof(dp));
dp[0][0] = 0;
for (int i = 1; i < (1 << n); ++i) {
for (int j = 0; j < n; ++j)
if ((i >> j) & 1)
for (int k = 0; k < n; ++k)
dp[i][j] = min(dp[i][j], dp[i - (1 << j)][k] + d(k, j));
}
cout << dp[(1 << n) - 1][0] << '\n';
return 0;
}
F - Unbranched
这里做的有点懵,贴一下代码
这里使用了 atcoder/all 头文件,添加方法:Click Here
#include <atcoder/all>
using mint = atcoder::modint1000000007;
int N, M, L;
mint f(int L) {
mint dp[303][303];
dp[0][0] = 1;
for (int i = 0; i < N; i++)
for (int j = 0; j <= i; j++) {
mint T = dp[i][j];
for (int k = 1; i + k <= N && j + k - 1 <= M && k <= L; k++) {
if (k > 1) dp[i + k][j + k] += T;
if (k == 2) T *= 500000004;
dp[i + k][j + k - 1] += T * k;
T *= N - i - k;
}
}
return dp[N][M];
}
int main() {
std::cin >> N >> M >> L;
std::cout << (f(L) - f(L - 1)).val();
return 0;
}
分类:
刷题笔记: AtCoder
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· 探究高空视频全景AR技术的实现原理
· 理解Rust引用及其生命周期标识(上)
· 浏览器原生「磁吸」效果!Anchor Positioning 锚点定位神器解析
· 没有源码,如何修改代码逻辑?
· 一个奇形怪状的面试题:Bean中的CHM要不要加volatile?
· 分享4款.NET开源、免费、实用的商城系统
· Obsidian + DeepSeek:免费 AI 助力你的知识管理,让你的笔记飞起来!
· MongoDB 8.0这个新功能碉堡了,比商业数据库还牛
· 白话解读 Dapr 1.15:你的「微服务管家」又秀新绝活了
· 全程不用写代码,我用AI程序员写了一个飞机大战
2020-04-01 剑指offer—单链表反转的三种实现方法
2020-04-01 排序算法总结