第一次 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. STP、PVST、MST协议

    • STP:生成树协议        ○ 阻止环形链路的广播风暴    • PVST:VLAN生成树        ○ 是STP的进阶版不仅能阻止广播风暴,还可以做到基于VLAN进行流量均衡.     ...

  2. 【详细】Python基础(一)

    @ 目录 前言 1. Python环境的搭建 1.1 python解释器的安装 1.2 pycharm的安装 2. Python基础语法 2.1 基本语法 2.2 数据类型 2.3 标识符与关键字 2 ...

  3. Java线程安全与锁优化,锁消除,锁粗化,锁升级

    线程安全的定义 来自<Java高并发实战>"当多个线程访问一个对象的时候,如果不用考虑这些线程在运行时环境下的调度和交替执行,也不需要进行额外的同步,或者在调用方法的时候进行任何 ...

  4. RAC上的DG搭建

    准备工作 修改rman_backup这个文件的所有者和所属组,修改为oracle用户的oinstall组的文件 #chown –R oracle:oinstall /rman_backup/ 主库和备 ...

  5. 爬虫系列 | 6、详解爬虫中BeautifulSoup4的用法

    bs4,全称BeautifulSoup 4 , 它是Python独有的一种解析方式.也就是说只有Python语言才可以通过这种方式去解析数据. BeautifulSoup 3 只支持Python2,所 ...

  6. ctfhub技能树—密码口令—弱口令

    什么是弱口令? "弱口令(weak password) 没有严格和准确的定义,通常认为容易被别人(他们有可能对你很了解)猜测到或被破解工具破解的口令均为弱口令. 弱口令指的是仅包含简单数字和 ...

  7. 入门OJ:Coin

    题目描述 你有n个硬币,第i硬币面值为ai,现在总队长想知道如果丢掉了某个硬币,剩下的硬币能组成多少种价值?(0价值不算) 输入格式 第一行一个整数n 第二行n个整数.,a1,a2-an. 1< ...

  8. 1.5V转3V电源芯片,1.5V转3V稳压芯片

    1.5V干电池的供电电压一般是0.9V-1.6V左右,因为供电电压不稳,所以需要1.5V转3V的稳压电源芯片,当0.9V-1.6V输入电压时,输出电压能稳定3V输出,给模块供电,MCU供电,LED灯供 ...

  9. inode占满导致No space left on device inode快速解决方法

    暂未发现其他比我这个更快的方法. 因为其他方法会展示那个非常卡的目录,导致效率极低.而我这个方法不会去展示那个目录. 查找占用的目录 find / -type d -size +1M -maxdept ...

  10. Zabbix监控虚拟机服务-告警与自动恢复-模板化

    上一篇文章测试了服务的告警与自动恢复:Zabbix监控虚拟机服务-告警与自动恢复 但是我是直接为某一个主机增加的监控项和触发器, 如果要让某一个自定义的监控项和触发器被很多机器共用,则需要创建模板 1 ...