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 ...
随机推荐
- python循环之for循环
当我们想让列表中的元素一个一个打印出时,用多个print()就显得代码很繁琐了,这是我们就可以用到循环 list_1 = ['one', 'two', 'three', 'four', 'five'] ...
- Eclipse 安装 ABAP 插件报错 Microsoft Visual C++ 2013 (x64) 快速解决
去官网下载Microsoft Visual C++ 2013 (x64) 安装 Download Visual C++ Redistributable Packages for Visual St ...
- 什么是oa软件?oa软件能做什么?
什么是OA软件? OA软件是办公自动化软件(Office Automation Software)的简称,是一种通过计算机技术,对办公业务流程进行管理和自动化处理的软件系统.它主要用于协调和管理企业内 ...
- Nim 枚举类型 对性能的影响
Nim 枚举类型 对性能的影响 继上一篇文章<Nim 概念 Concept 对性能的影响>后,我在想,既然 method 虚方法造成性能的影响很大,那么有没有更快的方法实现,当然是有的,那 ...
- Windows下使用C#和32feet.NET开发蓝牙传输功能的记录
引用的第三方Nuget库 32feet.NET 3.5.0 MaterialDesignColors MaterialDesignThemes Newtonsoft.Json 使用到的技术: XAML ...
- ElasticSearch之cat master API
命令样例如下: curl -X GET "https://localhost:9200/_cat/master?v=true&pretty" --cacert $ES_HO ...
- 在Windows操作系统中,使用powershell脚本批量删除、批量替换文件名
比如我们下载的mp3文件或者小说.评书里都带很多作者.网站等信息,如何批量一键删除掉多余的字段呢? 下面举例:批量删除文件名称 可以看到原文中,所有文件名中均包含"小番茄与火龙果-" ...
- Centos7——防火墙(Firewall)命令
centos防火墙根据系统大致有2种,一种是centos6时代的iptables:一种是centos7时代的firewalld: CentOS 7中防火墙是一个非常的强大的功能,在CentOS 6.5 ...
- DVWA Brute Force(暴力破解)全等级
Brute Force(暴力破解) 目录: Brute Force(暴力破解) 1.Low 2.Medium 3.High 方法1--Burp爆破 方法2--Python脚本爆破 4.Impossib ...
- Istio 为服务指定协议
1.背景 Istio 默认支持代理所有 TCP 流量.包括 HTTP.HTTPS.gRPC 以及原始 TCP 协议.但为了提供额外的能力,比如路由和丰富的指标,必须确定协议.协议可以被自动检测或者手动 ...