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的更多相关文章

  1. AtCoder Beginner Contest 100 2018/06/16

    A - Happy Birthday! Time limit : 2sec / Memory limit : 1000MB Score: 100 points Problem Statement E8 ...

  2. AtCoder Beginner Contest 052

    没看到Beginner,然后就做啊做,发现A,B太简单了...然后想想做完算了..没想到C卡了一下,然后还是做出来了.D的话瞎想了一下,然后感觉也没问题.假装all kill.2333 AtCoder ...

  3. AtCoder Beginner Contest 053 ABCD题

    A - ABC/ARC Time limit : 2sec / Memory limit : 256MB Score : 100 points Problem Statement Smeke has ...

  4. AtCoder Beginner Contest 136

    AtCoder Beginner Contest 136 题目链接 A - +-x 直接取\(max\)即可. Code #include <bits/stdc++.h> using na ...

  5. AtCoder Beginner Contest 137 F

    AtCoder Beginner Contest 137 F 数论鬼题(虽然不算特别数论) 希望你在浏览这篇题解前已经知道了费马小定理 利用用费马小定理构造函数\(g(x)=(x-i)^{P-1}\) ...

  6. AtCoder Beginner Contest 076

    A - Rating Goal Time limit : 2sec / Memory limit : 256MB Score : 100 points Problem Statement Takaha ...

  7. AtCoder Beginner Contest 079 D - Wall【Warshall Floyd algorithm】

    AtCoder Beginner Contest 079 D - Wall Warshall Floyd 最短路....先枚举 k #include<iostream> #include& ...

  8. AtCoder Beginner Contest 064 D - Insertion

    AtCoder Beginner Contest 064 D - Insertion Problem Statement You are given a string S of length N co ...

  9. AtCoder Beginner Contest 075 D - Axis-Parallel Rectangle【暴力】

    AtCoder Beginner Contest 075 D - Axis-Parallel Rectangle 我要崩溃,当时还以为是需要什么离散化的,原来是暴力,特么五层循环....我自己写怎么都 ...

  10. AtCoder Beginner Contest 075 C bridge【图论求桥】

    AtCoder Beginner Contest 075 C bridge 桥就是指图中这样的边,删除它以后整个图不连通.本题就是求桥个数的裸题. dfn[u]指在dfs中搜索到u节点的次序值,low ...

随机推荐

  1. Android 中的property_get/property_set

    Android 中的property_get/property_set 背景 在安卓中调试Linux驱动层以及应用层之间的一些功能时,需要获取一些属性. 参考: https://blog.csdn.n ...

  2. python基础-元组tuple( )

    元组的定义和操作 元组的特性: 元素数量 支持多个 元素类型 任意 下标索引 支持 重复元素 支持 可修改性 不支持 数据有序 是 使用场景 不可修改.可重复的 一批数据记录场景     # 定义元组 ...

  3. 一个用来画拉氏图的简单Python脚本

    技术背景 关于拉氏图的更多介绍,可以参考下这篇博客,这里简单引述一部分内容: Ramachandran plot(拉氏图)是由G. N. Ramachandran等人于1963年开发的,用来描述蛋白质 ...

  4. SpringBoot 接收Post请求参数,三种方式

    package net.cyb.demo.controller; import net.cyb.demo.domain.User; import net.cyb.demo.utils.JsonData ...

  5. 详解C#委托与事件

    在C#中,委托是一种引用类型的数据类型,允许我们封装方法的引用.通过使用委托,我们可以将方法作为参数传递给其他方法,或者将多个方法组合在一起,从而实现更灵活的编程模式.委托类似于函数指针,但提供了类型 ...

  6. 微软账号密码修改后提示密码错误的解决方法(远程桌面&smb共享访问等)

    众所周知,自从微软将Microsoft账户与Windows账号强制绑定后,使用起来便一直有诸多困难,在Microsoft Support和搜索引擎长期搜索解决方案未果,今天偶然在一个佬的博客翻到了这个 ...

  7. 苹果手机使用charles抓包无法下载charles证书

    苹果手机使用charles抓包无法下载charles证书的问题记录: 使用:chls.pro/ssl       --------无效 使用:http://chls.pro/ssl      ---- ...

  8. IntersectionObserver 实现图片懒加载

    背景 最近使用express做导航类型网站,因为这个是后端jade渲染,浏览器拿到页面之后,解析出来dom结构,导致100+的图片瞬间加载,严重浪费了宽带资源,加重服务器负担,因此打算延迟加载图片 模 ...

  9. Linux-makefile命令后面的-j4 -j8是什么意思?

    其实是指在编译指定的文件时用多少个线程进行编程的意思~ 相关命令示例如下: make zImage -j8 make modules -j8 --------------------------- m ...

  10. git 更新某个目录或文件

    不多说直接贴代码 更新文件 $ git fetch remote: Counting objects: 8, done. remote: Compressing objects: 100% (3/3) ...