AtCoder Beginner Contest 318
AtCoder Beginner Contest 318
A - Full Moon (atcoder.jp)
以\(M\)为首项,\(P\)为公差,看\(1 \sim N\)里包含了多少项的个数
#include<bits/stdc++.h>
using i64 = long long;
using namespace std;
typedef pair<i64, i64> PII;
int main() {
ios::sync_with_stdio(false);
cin.tie(nullptr);
int N,M,P;
cin >> N >> M >> P;
cout << 1ll * max(N - M, 0) / P + (N >= M) << '\n';
return 0;
}
B - Overlapping sheets (atcoder.jp)
数据不大,直接枚举即可
#include <bits/stdc++.h>
#define debug(a) cout<<#a<<"="<<a<<'\n';
using namespace std;
using i64 = long long;
typedef pair<i64, i64> PII;
int main() {
ios::sync_with_stdio(false);
cin.tie(nullptr);
int N;
cin >> N;
i64 ans = 0;
vector<bitset<110>> g(110, 0);
for (int i = 0; i < N; i ++) {
int A, B, C, D;
cin >> A >> B >> C >> D;
for (int j = A; j < B; j ++)
for (int k = C; k < D; k ++)
g[j][k] = 1;
}
for (int i = 0; i < 100; i ++)
for (int j = 0; j < 100; j ++)
ans += g[i][j];
cout << ans << '\n';
return 0;
}
C - Blue Spring (atcoder.jp)
题意就是在\(N\)天的旅游中,每天会花费\(A_i\)元,但是可以花费\(P\)元使得\(D\)天的花费免费,这\(D\)天可以是分开的.
我们可以将每天的费用从大到小排序,做一个前缀和,将\(D\)天内的花费与\(P\)做一个比较,取其小的费用即可
#include <bits/stdc++.h>
#define debug(a) cout<<#a<<"="<<a<<'\n';
using namespace std;
using i64 = long long;
typedef pair<i64, i64> PII;
int main() {
ios::sync_with_stdio(false);
cin.tie(nullptr);
i64 N, D;
i64 ans = 0, P;
cin >> N >> D >> P;
vector<i64> F(N + D + 1);
for (int i = 1; i <= N; i ++)
cin >> F[i];
sort(F.begin() + 1, F.begin() + N + 1,greater<>());
for (int i = 1; i <= N + D; i ++)
F[i] += F[i - 1];
for (int i = D; i <= N + D; i += D)
ans += min(P, F[i] - F[i - D]);
cout << ans << '\n';
return 0;
}
D - General Weighted Max Matching (atcoder.jp)
\(N\)最多只有\(16\),可以直接\(dfs\)暴搜(
#include <bits/stdc++.h>
#define debug(a) cout<<#a<<"="<<a<<'\n';
using namespace std;
using i64 = long long;
typedef pair<i64, i64> PII;
int main() {
ios::sync_with_stdio(false);
cin.tie(nullptr);
int N;
cin >> N;
vector<vector<int>> g(N + 1, vector<int>(N + 1));
for (int i = 1, D; i < N; i ++) {
for (int j = i + 1; j <= N; j++) {
cin >> g[i][j];
g[j][i] = g[i][j];
}
}
bitset<20> vis;
i64 ans = 0;
auto dfs = [&](auto self, int n, i64 sum) ->void{
if (n > N) {
ans = max(ans, sum);
return ;
}
if (!vis[n]) {
vis[n] = 1;
for (int i = n + 1; i <= N; i ++) {
if (!vis[i]) {
vis[i] = 1;
self(self, n + 1, sum + g[i][n]);
vis[i] = 0;
}
}
vis[n] = 0;
}
self(self, n + 1, sum);
};
dfs(dfs,1,0);
cout << ans << '\n';
return 0;
}
E - Sandwiches (atcoder.jp)
对于\(A_i\)和\(A_k\),设其中间的长度为\(L\),当只有这两个点相等时,则这两个点的贡献为\(L\),若\(A_i\)左边还有点,则它们可以与\(A_k\)产生\(Num_左 \times L\)的贡献,同理,\(A_k\)右边还有点的话则与\(A_i\)产生\(Num_右 \times L\)的贡献,所以对于相邻的两个值相等的点产生的贡献为\(L(k-i-1(不包括A_i和A_k)) \times 左边点 \times 右边点\)
#include <bits/stdc++.h>
#define debug(a) cout<<#a<<"="<<a<<'\n';
using namespace std;
using i64 = long long;
typedef pair<i64, i64> PII;
int main() {
ios::sync_with_stdio(false);
cin.tie(nullptr);
int N;
cin >> N;
vector<i64> A(N), g[N + 1];
for (int i = 0; i < N; i ++) {
cin >> A[i];
g[A[i]].emplace_back(i);
}
i64 ans = 0;
for (int i = 1; i <= N; i ++) {
for (int j = 1; j < g[i].size(); j ++) {
ans += (g[i][j] - g[i][j - 1] - 1) * j * (g[i].size() - j);
}
}
cout << ans << '\n';
return 0;
}
AtCoder Beginner Contest 318的更多相关文章
- 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 ...
随机推荐
- 洛谷 P1226 快速幂
题目链接:快速幂 思路 简单快速幂模板.a ^ 17 = (a ^ 2) ^ 8 * a,此时pow()中的y就可以视为17 -> 8(y >>= 1),pow()中的x就是底数a ...
- OpenLiveWriter的代码高亮插件
可参考如下方法: https://www.cnblogs.com/mq0036/p/12101912.html 0. 最新插件下载地址:Memento.OLW_V1.0.0.5.7z 1. 找到Ope ...
- SAM & 广义 SAM & SA 学习笔记
SAM 定理 SAM 由 parent 树与一张 DAG 构成,他们共用点集. \(endpos(s)\) 表示 \(s\) 出现的所有位置上最后一个字符所处位置的集合. SAM 中 DAG 上每条路 ...
- Linux开发人员常用命令
常用查询命令 # 查看ip地址 ip addr show # 查看当前目录路径 pwd # 当前目录下模糊查找文件 find / -name "*.pdf" 查看运行中进程 ps ...
- Bom浏览器对象模型 -- 手稿
------------恢复内容开始------------ ------------恢复内容结束------------ ------------恢复内容开始------------ ------- ...
- ScreenToGif:一款开源免费且好用的录屏转Gif软件
ScreenToGif介绍 GitHub上的介绍:此工具允许您记录屏幕的选定区域.来自网络摄像头的实时提要或来自草图板的实时绘图.之后,您可以编辑动画并将其保存为 gif.apng.视频.psd 或 ...
- supervisor.conf部署及维护
启动服务 supervisord -c /etc/supervisord.conf 启动服务 supervisorctl start 关闭服务 supervisorctl stop
- Django DRF @action 装饰器
@action 装饰器在Django REST Framework (DRF) 中非常有用,它可以帮助你在ViewSet中创建自定义的动作,而不仅仅是依赖标准的CRUD操作(Create, Read, ...
- oeasy教您玩转vim - 16 - # 行内贴靠
行头行尾 回忆上节课内容 跳跃 向前跳跃是 f 向后跳跃是 F 继续 保持方向是 ; 改变方向是 , 可以加上 [count] 来加速 还有什么好玩的吗? 动手 #这次还是用无配置的方式启动 vi - ...
- oeasy教您玩转vim - 51 - # 读写文件
读写文件 回忆上节课内容 命令行的光标控制 方向键️️️️️可以控制左右移动 shift+️️️️️按照word左右移动光标 ctrl+b 到开头begin ctrl+e 到结尾end ctrl+w ...