第一次 ak cf 的正式比赛,不正式的是寒假里 div4 的 Testing Round,好啦好啦不要问我为什么没有 ak div4 了,差一题差一题 =。=

不知不觉已经咕了一个月了2333。

比赛链接:https://codeforces.com/contest/1462

A. Favorite Sequence

题解

模拟即可。

代码

#include <bits/stdc++.h>
using namespace std;
int main() {
ios::sync_with_stdio(false);
cin.tie(nullptr);
int t;
cin >> t;
while (t--) {
int n;
cin >> n;
deque<int> d;
for (int i = 0; i < n; i++) {
int x;
cin >> x;
d.push_back(x);
}
while (not d.empty()) {
cout << d.front() << ' ';
d.pop_front();
if (not d.empty()) {
cout << d.back() << ' ';
d.pop_back();
}
}
cout << "\n";
}
return 0;
}

B. Last Year's Substring

题解

枚举余下首尾子串的长度即可。

代码

#include <bits/stdc++.h>
using namespace std;
int main() {
ios::sync_with_stdio(false);
cin.tie(nullptr);
int t;
cin >> t;
while (t--) {
int n;
cin >> n;
string s;
cin >> s;
bool ok = false;
for (int i = 0; i <= 4; i++) {
string t = s.substr(0, i) + s.substr(n - 4 + i);
ok or_eq t == "2020";
}
cout << (ok ? "YES" : "NO") << "\n";
}
return 0;
}

C. Unique Number

题解

最小的数一定最短,所以从 9~1 依次减即可,也因此不会存在 \(x\) 减不完的情况。

代码

#include <bits/stdc++.h>
using namespace std;
int main() {
ios::sync_with_stdio(false);
cin.tie(nullptr);
int t;
cin >> t;
while (t--) {
int x;
cin >> x;
if (x > 45) {
cout << -1 << "\n";
continue;
}
string digit;
for (int i = 9; i >= 1; i--) {
if (x >= i) {
x -= i;
digit += '0' + i;
}
}
cout << string(digit.rbegin(), digit.rend()) << "\n";
}
return 0;
}

拓展

最大的数一定最长,所以从 1~9 依次减即可,也因此需要判断 \(x\) 减不完的情况。

代码

#include <bits/stdc++.h>
using namespace std;
int main() {
ios::sync_with_stdio(false);
cin.tie(nullptr);
int t;
cin >> t;
while (t--) {
int x;
cin >> x;
if (x > 45) {
cout << -1 << "\n";
continue;
}
string s;
for (int i = 1; i <= 9; i++) {
if (x < i and x != 0) {
x += i - 1;
s.pop_back();
}
if (x >= i) {
x -= i;
s += '0' + i;
}
}
cout << string(s.rbegin(), s.rend()) << "\n";
}
return 0;
}

D. Add to Neighbour and Remove

题解

枚举最后剩下几个数即可。

代码

#include <bits/stdc++.h>
using namespace std;
int main() {
ios::sync_with_stdio(false);
cin.tie(nullptr);
int t;
cin >> t;
while (t--) {
int n;
cin >> n;
vector<int> a(n);
int sum = 0;
for (int i = 0; i < n; i++) {
cin >> a[i];
sum += a[i];
}
int ans = INT_MAX;
for (int i = 1; i <= n; i++) {
if (sum % i == 0) {
bool ok = true;
int cur = 0;
for (int j = 0; j < n; j++) {
cur += a[j];
if (cur > sum / i) {
ok = false;
} else if (cur == sum / i) {
cur = 0;
}
}
if (ok) {
ans = min(ans, n - i);
}
}
}
cout << ans << "\n";
}
return 0;
}

E2. Close Tuples (hard version)

题解

将值排序,然后枚举所有值,找到以当前值为最小值且符合题意的元组的最大长度,答案即 \(\sum \limits _{i = 1}^{n} C_{len - 1}^{m - 1}\) 。

代码

#include <bits/stdc++.h>
using namespace std;
constexpr int N = 1e6 + 100;
constexpr int MOD = 1e9 + 7; int fac[N], inv[N]; int binpow(int a, int b) {
int res = 1;
while (b) {
if (b & 1) res = 1LL * res * a % MOD;
a = 1LL * a * a % MOD;
b >>= 1;
}
return res;
} int C(int n, int m){
if(m < 0 or m > n) return 0;
return 1LL * fac[n] * inv[m] % MOD * inv[n - m] % MOD;
} void Init(){
fac[0] = 1;
for (int i = 1; i < N; i++) fac[i] = 1LL * fac[i - 1] * i % MOD;
inv[N - 1] = binpow(fac[N - 1], MOD - 2);
for (int i = N - 2; i >= 0; i--) inv[i] = 1LL * inv[i + 1] * (i + 1) % MOD;
} int main() {
ios::sync_with_stdio(false);
cin.tie(nullptr);
Init();
int t;
cin >> t;
while (t--) {
int n, m, k;
cin >> n >> m >> k;
vector<int> a(n);
for (int i = 0; i < n; i++) {
cin >> a[i];
}
sort(a.begin(), a.end());
int64_t ans = 0;
int l = 0, r = 0;
while (l < n) {
while (r < n and a[r] - a[l] <= k) {
++r;
}
if (a[r - 1] - a[l] <= k) {
ans = (ans + C(r - l - 1, m - 1)) % MOD;
}
++l;
}
cout << ans << "\n";
}
return 0;
}

F. The Treasure of The Segments

题解

枚举所有区间即可,满足以下两种情况之一的区间需要删掉:

  • 右端点小于所枚举区间的左端点
  • 左端点大于所枚举区间的右端点

将区间左右端点分别排序,每次二分查找需要删掉区间的个数即可。

代码

#include <bits/stdc++.h>
using namespace std;
int main() {
ios::sync_with_stdio(false);
cin.tie(nullptr);
int t;
cin >> t;
while (t--) {
int n;
cin >> n;
vector<int> L(n), R(n);
vector<pair<int, int>> seg(n);
for (int i = 0; i < n; i++) {
cin >> L[i] >> R[i];
seg[i] = {L[i], R[i]};
}
sort(L.begin(), L.end());
sort(R.begin(), R.end());
int ans = INT_MAX;
for (auto [x, y] : seg) {
int res = 0;
int l = upper_bound(L.begin(), L.end(), y) - L.begin();
res += n - l;
int r = lower_bound(R.begin(), R.end(), x) - R.begin();
res += r;
ans = min(ans, res);
}
cout << ans << "\n";
}
return 0;
}

Codeforces Round #690 (Div. 3)的更多相关文章

  1. Codeforces Round #690 (Div. 3) E2. Close Tuples (hard version) (数学,组合数)

    题意:给你一长度为\(n\)的序列(可能含有相等元素),你要找到\(m\)个位置不同的元素使得\(max(a_{i-1},a_{i_2},...,a_{i_m})-min(a_{i-1},a_{i_2 ...

  2. Codeforces Round #366 (Div. 2) ABC

    Codeforces Round #366 (Div. 2) A I hate that I love that I hate it水题 #I hate that I love that I hate ...

  3. Codeforces Round #354 (Div. 2) ABCD

    Codeforces Round #354 (Div. 2) Problems     # Name     A Nicholas and Permutation standard input/out ...

  4. Codeforces Round #368 (Div. 2)

    直达–>Codeforces Round #368 (Div. 2) A Brain’s Photos 给你一个NxM的矩阵,一个字母代表一种颜色,如果有”C”,”M”,”Y”三种中任意一种就输 ...

  5. cf之路,1,Codeforces Round #345 (Div. 2)

     cf之路,1,Codeforces Round #345 (Div. 2) ps:昨天第一次参加cf比赛,比赛之前为了熟悉下cf比赛题目的难度.所以做了round#345连试试水的深浅.....   ...

  6. Codeforces Round #279 (Div. 2) ABCDE

    Codeforces Round #279 (Div. 2) 做得我都变绿了! Problems     # Name     A Team Olympiad standard input/outpu ...

  7. Codeforces Round #262 (Div. 2) 1003

    Codeforces Round #262 (Div. 2) 1003 C. Present time limit per test 2 seconds memory limit per test 2 ...

  8. Codeforces Round #262 (Div. 2) 1004

    Codeforces Round #262 (Div. 2) 1004 D. Little Victor and Set time limit per test 1 second memory lim ...

  9. Codeforces Round #371 (Div. 1)

    A: 题目大意: 在一个multiset中要求支持3种操作: 1.增加一个数 2.删去一个数 3.给出一个01序列,问multiset中有多少这样的数,把它的十进制表示中的奇数改成1,偶数改成0后和给 ...

随机推荐

  1. 【高精度】计算2的N次方

    题目相关 [题目描述] 任意给定一个正整数N(N≤100),计算2的n次方的值. [输入] 输入一个正整数N. [输出] 输出2的N次方的值. [输入样例] 5 [输出样例] 32 分析 本题考察的是 ...

  2. 浅谈localStorage的使用场景和优劣势,以及sessionStorage和cookie

    一.localStorage,sessionStorage,cookie的简单介绍 localStorage:仅在客户端存储不参与服务器通信,存储大小一般为5M,如果不是人为清除,那么即使是关闭浏览器 ...

  3. 如何在 Vite 中使用 Element UI + Vue 3

    在上篇文章<2021新年 Vue3.0 + Element UI 尝鲜小记>里,我们尝试使用了 Vue CLI 创建 Vue 3 + Element UI 的项目,而 Vue CLI 实际 ...

  4. Java虚拟机常用的性能监控工具

    基础故障处理工具 jps: 虚拟机进程状况工具 功能:来处正在运行的虚拟机进程,并显示虚拟机执行主类名称,以及本地虚拟机唯一ID. 它是使用频率最高的命令行工具,因为其他JDK工具大多需要输入他查询到 ...

  5. Linux学习笔记 | docker基本命令

    Docker的三大核心概念:镜像.容器.仓库 镜像:类似虚拟机的镜像.用俗话说就是安装文件. 容器:类似一个轻量级的沙箱,容器是从镜像创建应用运行实例,可以将其启动.开始.停止.删除.而这些容器都是相 ...

  6. VBA实现相同行合并

    帮人捣鼓了个VBA代码用来实现多行合并,具体需求为:列2/列3/列4 相同的情况下,则对应的行合并为一行,且列1用空格隔开,列5则相加: (对大多数办公室职员,VBA还算是提高效率的一个利器吧) 最终 ...

  7. 避免用using包装DbContext【翻译】

    EF和EF Core 的DbContext类实现IDisposable接口.因此,很多最佳编程实践中都建议你将它们放在一个using()块中.不幸的是,至少在Web应用程序中,这样做通常不是一个好主意 ...

  8. RocketMQ—消息队列入门

    消息队列功能介绍 字面上说的消息队列是数据结构中"先进先出"的一种数据结构,但是如果要求消除单点故障,保证消息传输可靠性,应对大流量的冲击,对消息队列的要求就很高了.现在互联网的& ...

  9. SpringBoot 好“吃”的启动原理

    原创:西狩 编写日期 / 修订日期:2020-12-30 / 2020-12-30 版权声明:本文为博主原创文章,遵循 CC BY-SA-4.0 版权协议,转载请附上原文出处链接和本声明. 不正经的前 ...

  10. 如何在K8s,Docker-Compose注入镜像Tag

    最近在做基于容器的CI/CD, 一个朴素的自动部署的思路是: 从Git Repo打出git tag,作为镜像Tag ssh远程登录到部署机器 向部署环境注入镜像Tag,拉取镜像,重新部署 下面分享我是 ...