AtCoder Beginner Contest 167 (A~F,DEF Good)
比赛链接:https://atcoder.jp/contests/abc167/tasks
AB水题,
C - Skill Up
题意:
- 初始时 \(m\) 个算法的能力均为 \(0\),\(n\) 次中每次可以花费 \(c_i\) 元提升 \(m\) 个算法的能力(提升程度可能不等),问 \(m\) 个算法能力都提升到不低于 \(x\) 的最少花费。
思路:
一开始想写DP的,但发现数据范围不是很大 \((n\le 15)\) ,那么直接枚举即可了
int n, m, x;
int c[15], a[15][15];
int M[15], Min = 1e9, cost;
void chmin(int &a, int b) { return (void)(a > b ? a = b : a = a); }
void chmax(int &a, int b) { return (void)(a < b ? a = b : a = a); }
bool check() {
for (int i = 0; i < m; ++i) if (M[i] < x) return 0;
return 1;
}
void dfs(int i) {
if (i == n) {
if (check()) chmin(Min, cost);
return ;
}
cost += c[i];
for (int j = 0; j < m; ++j) M[j] += a[i][j];
dfs(i + 1);
cost -= c[i];
for (int j = 0; j < m; ++j) M[j] -= a[i][j];
dfs(i + 1);
}
int main() {
cin.tie(nullptr)->sync_with_stdio(false);
cin >> n >> m >> x;
for (int i = 0; i < n; ++i) {
cin >> c[i];
for (int j = 0; j < m; ++j) cin >> a[i][j];
}
dfs(0);
cout << (Min == 1e9 ? -1 : Min);
}
D - Teleporter
题意:
- \(1\sim n\) 个城镇每个城镇有一个传送点可以传送到其他城镇,问从第一个城镇出发传送 \(k\) 次后所在的城镇。
思路:
模拟一下样例就知道传送过程中肯定存在环,那么我们标记环路起点,加上传送次数对环路长度的模值即可,需要注意有可能先在一些城镇间传送后才进入环路。
const int N = 2e5 + 10;
ll n, k;
ll a[N], pre[N];
int main() {
cin.tie(nullptr)->sync_with_stdio(false);
cin >> n >> k;
for (int i = 1; i <= n; ++i) cin >> a[i];
int now = 1;
ll cnt = 0;
while (k--) {
now = a[now];
if (pre[now])k %= cnt - pre[now];
pre[now] = cnt++;
}
cout << now;
}
E - Colorful Blocks
题意:
- 给 \(n\) 个方块染色,可以使用 \(m\) 个颜色,要求最多有 \(k\) 对相邻方块同色。
思路:
\(ans = \sum\limits_{i = 0}^km*C_{n-1}^i*(m - 1)^{n-1-i}\)
解释一下,第 \(1\) 个方块可以染 \(m\) 种颜色,从余下 \(n - 1\) 个方块中选取 \(i\) 个方块,这 \(i\) 个方块组成同色的 \(i\) 对方块,它们的颜色与左相邻的方块相同,其余的 \(n - 1 - i\) 个方块因为不与左相邻方块同色,每个可以染 \(m - 1\) 个颜色。
代码书写上用逆序处理一下,同时独立出 \(add + mul\) 模块防止写错细节
const int N = 2e5 + 10, mod = 998244353;
ll fac[N];
ll add(ll a, ll b) {return (a + b) % mod;}
ll mul(ll a, ll b) {return a * b % mod;}
ll qpow(ll a, ll b) {
ll ans = 1;
for (; b; b >>= 1, a = mul(a, a)) if (b & 1) ans = mul(ans, a);
return ans;
}
ll inv(ll n) {return qpow(n, mod - 2);}
ll C(ll n, ll m) {
return mul(fac[n], mul(inv(fac[m]), inv(fac[n - m])));
}
int main() {
cin.tie(nullptr)->sync_with_stdio(false);
fac[0] = 1;
for (int i = 1; i < N; ++i) fac[i] = mul(fac[i - 1], i);
ll n, m, k;
cin >> n >> m >> k;
ll ans = 0;
for (int i = 0; i <= k; ++i)
ans = add(ans, mul(m, mul(C(n - 1, i), qpow(m - 1, n - 1 - i))));
cout << ans;
}
F - Bracket Sequencing
题意:
- 能否将一些括号串编排为合法串。
思路:
这道题不会,参考了一下这个大佬的博客:Here
详细思路:GYM - 101341A
const int M = 1e6 + 100;
int l[M], r[M];
int id[M], tp[M];
int main() {
int n; cin >> n;
for (int i = 0; i < n; i++) {
string s; cin >> s;
int x = 0, y = 0;
for (char c : s) {
if (c == '(') ++x;
else if (x) --x;
else ++y;
}
l[i] = x, r[i] = y, id[i] = i;
if (y == 0) tp[i] = 1;
else if (x == 0) tp[i] = 4;
else if (x >= y) tp[i] = 2;
else tp[i] = 3;
}
sort(id, id + n, [&] (int a, int b) {
if (tp[a] != tp[b]) return tp[a] < tp[b];
if (tp[a] == 2) {
if (r[a] != r[b]) return r[a] < r[b];
else return l[a] > l[b];
}
if (tp[a] == 3) return l[a] > l[b];
return false;
});
int sum = 0;
for (int i = 0; i < n; i++) {
sum -= r[id[i]];
if (sum < 0) break;
sum += l[id[i]];
}
cout << (sum == 0 ? "Yes" : "No");
}
AtCoder Beginner Contest 167 (A~F,DEF Good)的更多相关文章
- Atcoder Beginner Contest 156E(隔板法,组合数学)
#define HAVE_STRUCT_TIMESPEC #include<bits/stdc++.h> using namespace std; ; ; long long fac[N] ...
- AtCoder Beginner Contest 254(D-E)
Tasks - AtCoder Beginner Contest 254 D - Together Square 题意: 给定一个N,找出所有不超过N的 ( i , j ),使得( i * j )是一 ...
- Atcoder Beginner Contest 155D(二分,尺取法,细节模拟)
二分,尺取法,细节模拟,尤其是要注意a[i]被计算到和a[i]成对的a[j]里时 #define HAVE_STRUCT_TIMESPEC #include<bits/stdc++.h> ...
- Atcoder Beginner Contest 140E(多重集,思维)
#define HAVE_STRUCT_TIMESPEC#include<bits/stdc++.h>using namespace std;multiset<long long&g ...
- Atcoder Beginner Contest 139E(模拟,思维)
#define HAVE_STRUCT_TIMESPEC#include<bits/stdc++.h>using namespace std;int n;int a[1007][1007] ...
- AtCoder Beginner Contest 086 (ABCD)
A - Product 题目链接:https://abc086.contest.atcoder.jp/tasks/abc086_a Time limit : 2sec / Memory limit : ...
- AtCoder Beginner Contest 127 D,E,F
D Integer Cards 题意:先给出n个数字,然后可以有m次操作,每次操作以数字对(x,y)表示最多能选x个数字把它变成y,问经历m次操作后n个数字和最大为多少? 解法:一个明显正确的做法是: ...
- 【AtCoder Beginner Contest 181】A~F题解
越学越菜系列 于2020.11.2,我绿了(错乱) A - Heavy Rotation 签到题,奇数Black,偶数White. code: #include<bits/stdc++.h> ...
- AtCoder Beginner Contest 085(ABCD)
A - Already 2018 题目链接:https://abc085.contest.atcoder.jp/tasks/abc085_a Time limit : 2sec / Memory li ...
- AtCoder Beginner Contest 084(AB)
A - New Year 题目链接:https://abc084.contest.atcoder.jp/tasks/abc084_a Time limit : 2sec / Memory limit ...
随机推荐
- 龙芯发布 .NET 8 SDK 8.0.100-ea1(试用版)
随着.NET 8的发布,国内的社区朋友们也很关心龙芯.NET 团队对于Loongarch .NET 8的发布时间,目前从龙芯.NET编译器团队已经在龙芯.NET 官网上发布龙芯.NET 8 SDK-8 ...
- 【ASP.NET Core】MVC过滤器:常见用法
前面老周给大伙伴们演示了过滤器的运行流程,大伙只需要知道下面知识点即可: 1.过滤器分为授权过滤.资源访问过滤.操作方法(Action)过滤.结果过滤.异常过滤.终结点过滤.上一次咱们没有说异常过滤和 ...
- 数据可视化工具 ,不会写 SQL 代码也能做数据分析
数据可视化工具可以帮助人们以直观.易于理解的方式展现和分析数据.这些工具使得即使不会写 SQL 代码的人也能进行数据分析,并从中获得有价值的信息和见解. 本文将详细介绍几种常用的数据可视化工具及其功能 ...
- [USACO2007OPENS] Fliptile S
题目描述 FJ 知道,智商高的奶牛产奶量也大,所以他为奶牛们准备了一个翻动瓦片的益智游戏. 在一个 \(M \times N\) 的方阵上(\(1 \leq M,N \leq 15\)),每个格子都有 ...
- [ABC246G] Game on Tree 3
Problem Statement There is a rooted tree with $N$ vertices, Vertex $1$ being the root. For each $i = ...
- 使用C#如何监控选定文件夹中文件的变动情况?
目录 1.前言 2.效果 3.具体实现 页面设计 全部代码 FileSystemWatcher的介绍 FileSystemWatcher的构造函数 FileSystemWatche ...
- 如何用python脚本制作生成CANdbc
最近在工作中,有同事拿了一个excel的dbc表格,在用官方的dbc工具一个一个创建信号,大概看了一下共累计20多个节点,300多个信号,居然在手动处理,顿感无语.. 于是在网络上搜相关的dbc 通过 ...
- JavaFx之播放MP4(二十七)
JavaFx之播放MP4(二十七) JavaFX 视频和音频支持,由 JavaFX 媒体类 Media.MediaPlayer.MediaView 和 AudioClip 提供. import jav ...
- Programming Abstractions in C阅读笔记:p196
<Programming Abstractions in C>学习第63天,p196总结.涉及到编程之外的知识,依然是读起来很费劲,需要了解作者在书中提到的人物(Edouard Lucas ...
- C++产生N以内的随机整数
C++产生N(这里N=100)以内的随机整数的例子: #include <iostream> #include <ctime> using namespace std; int ...