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

A - Road To Zero

题意

有两个非负整数 x, y 以及两种操作:

  • 支付 a 点代价使其中一个数加一或减一
  • 支付 b 点代价使两个数都加一或减一

问使二者为 0 的最小代价。

思路

把较大的数减至与较小数相等再选取 min(2 * a, b) 把二者减为 0 即可。

代码

#include <bits/stdc++.h>
using namespace std; void solve() {
long long x, y, a, b; cin >> x >> y >> a >> b;
cout << min(2 * a, b) * min(x, y) + a * (max(x, y) - min(x, y)) << "\n";
} int main() {
int t; cin >> t;
while (t--) solve();
}

B - Binary Period

题意

给定 01 串 t,构造 01 串 s,要求满足:

  • 长度不超过 2 * | t |
  • t 为 s 的一个子序列
  • s 由最短的字符串重复而成

思路

如果 t 中只含有一种字符直接输出 t 即可,否则对于 t 中的每位均用“01”代替。

代码

#include <bits/stdc++.h>
using namespace std; void solve() {
string t; cin >> t;
int zero = 0, one = 0;
for (char c : t)
if (c == '0') zero = 1;
else one = 1;
if (zero + one == 1) cout << t << "\n";
else {
for (int i = 0; i < t.size(); i++)
cout << "01";
cout << "\n";
}
} int main() {
int t; cin >> t;
while (t--) solve();
}

C - Yet Another Counting Problem

题意

给你两个正整数 a, b,回答 q 次询问:[l, r] 区间中有多少数 x % a % b != x % b % a 。

思路

观察到条件为 x % a % b != x % b % a,可以联想到 (x + lcm(a, b)) % a % b != (x + lcm(a, b)) % b % a ,所以只需计算 [1, lcm] 区间内满足条件的数的个数,然后计算 [1, l - 1], [1, r] 中各有多少个长为 lcm 的区间,考虑到可能有不完全包含区间,所以可以计算 [1, lcm] 内的前缀和,查询长度对 lcm 取余对应的前缀和即为不完全包含区间中满足条件的数的个数。

代码

#include <bits/stdc++.h>
using LL = long long;
using namespace std; void solve() {
int a, b, q; cin >> a >> b >> q;
int lcm = a * b / __gcd(a, b);
int cnt[lcm + 1] = {};
for (int i = 1; i <= lcm; i++) {
cnt[i] = cnt[i - 1] + (i % a % b != i % b % a);
}
auto f = [&] (LL n) -> LL {
return cnt[lcm] * (n / lcm) + cnt[n % lcm];
};
for (int i = 0; i < q; i++) {
LL l, r; cin >> l >> r;
cout << f(r) - f(l - 1) << " \n"[i == q - 1];
}
} int main() {
int t; cin >> t;
while (t--) solve();
}

D - Multiple Testcases

题意

将 n 个数分为尽可能少的数组,要求每个数组中大于等于 i 的数不超过 ci 个。

思路

一种较为简便的方法是:利用后缀和算出大于等于 i 的数共有多少个,最少需要的数组即为 $max \lceil \frac{n_i}{c_i} \rceil$,之后从小到大循环推入数组元素。但是这种贪心的原理仍有待证明。

代码

#include <bits/stdc++.h>
using namespace std;
int main() {
int n, k; cin >> n >> k;
int suf[k + 1] = {};
int m[n]; for (int &i : m) cin >> i, ++suf[i - 1];
int c[k]; for (int &i : c) cin >> i;
int ans = 0;
for (int i = k - 1; i >= 0; i--) {
suf[i] += suf[i + 1];
ans = max(ans, (suf[i] - 1) / c[i] + 1);
}
vector<int> vec[ans];
sort(m, m + n);
for (int i = 0; i < n; i++)
vec[i % ans].push_back(m[i]);
cout << ans << "\n";
for (auto v : vec) {
cout << v.size();
for (auto i : v) cout << ' ' << i;
cout << "\n";
}
}

Educational Codeforces Round 86 (Div. 2)的更多相关文章

  1. Educational Codeforces Round 84 (Div. 2)

    Educational Codeforces Round 84 (Div. 2) 读题读题读题+脑筋急转弯 = =. A. Sum of Odd Integers 奇奇为奇,奇偶为偶,所以n,k奇偶性 ...

  2. Educational Codeforces Round 58 Div. 2 自闭记

    明明多个几秒就能场上AK了.自闭. A:签到. #include<iostream> #include<cstdio> #include<cmath> #inclu ...

  3. Educational Codeforces Round 47 (Div 2) (A~G)

    目录 Codeforces 1009 A.Game Shopping B.Minimum Ternary String C.Annoying Present D.Relatively Prime Gr ...

  4. Educational Codeforces Round 46 (Div 2) (A~G)

    目录 Codeforces 1000 A.Codehorses T-shirts B.Light It Up C.Covered Points Count(差分) D.Yet Another Prob ...

  5. Educational Codeforces Round 45 (Div 2) (A~G)

    目录 Codeforces 990 A.Commentary Boxes B.Micro-World C.Bracket Sequences Concatenation Problem D.Graph ...

  6. Educational Codeforces Round 85 (Div. 2)

    题目链接:https://codeforces.com/contest/1334 A. Level Statistics 题意 一个关卡有玩家的尝试次数和通关次数,按时间顺序给出一个玩家 $n$ 个时 ...

  7. Educational Codeforces Round 119 (Div. 2), (C) BA-String硬着头皮做, 能做出来的

    题目链接 Problem - C - Codeforces 题目 Example input 3 2 4 3 a* 4 1 3 a**a 6 3 20 **a*** output abb abba b ...

  8. Educational Codeforces Round 108 (Div. 2), C map套vector存储

    地址  Problem - C - Codeforces 题目 题意 一个学校有n个人参加比赛,他们分别属于ui队,每个人的能力值为si 当每个队需要1~n个人的时候,这个学校能参加的人的能力值和最大 ...

  9. Educational Codeforces Round 62 Div. 2

    突然发现上一场edu忘记写了( A:签到. #include<iostream> #include<cstdio> #include<cmath> #include ...

随机推荐

  1. LeetCode 二分查找模板 I

    模板 #1: int binarySearch(vector<int>& nums, int target){ if(nums.size() == 0) return -1; in ...

  2. 【Sphinx】 为Python自动生成文档

    sphinx 前言 Sphinx是一个可以用于Python的自动文档生成工具,可以自动的把docstring转换为文档,并支持多种输出格式包括html,latex,pdf等 开始 建一个存放文档的do ...

  3. Redis Cluster 集群节点信息 维护篇(二)

    集群信息文件: # cluster 集群内部信息对应文件,由集群自动维护. /data/soft/redis/6379data/nodes-6379.conf 集群信息查看: ./redis-trib ...

  4. Payment Spring Boot 1.0.4.RELEASE 发布,最易用的微信支付 V3 实现

    Payment Spring Boot 是微信支付V3的Java实现,仅仅依赖Spring内置的一些类库.配置简单方便,可以让开发者快速为Spring Boot应用接入微信支付. 欢迎ISSUE,欢迎 ...

  5. Pycharm同时执行多个脚本文件

    Pycharm同时执行多个脚本文件 设置Pycharm使它可以同时执行多个程序 打开Pycharm 找到Run,点击确认 点击Edit Configurations 右上角Allow parallel ...

  6. 【Python】在CentOS6.8中安装pip9.0.1和setuptools33.1

    wget https://bootstrap.pypa.io/ez_setup.py python ez_setup.py install --如果这个文件安装需要下载的文件无法下载的话,手动下载,放 ...

  7. Objects as Points:预测目标中心,无需NMS等后处理操作 | CVPR 2019

    论文基于关键点预测网络提出CenterNet算法,将检测目标视为关键点,先找到目标的中心点,然后回归其尺寸.对比上一篇同名的CenterNet算法,本文的算法更简洁且性能足够强大,不需要NMS等后处理 ...

  8. ctfhub技能树—信息泄露—git泄露—Log

    什么是git泄露? 当前大量开发人员使用git进行版本控制,对站点自动部署.如果配置不当,可能会将.git文件夹直接部署到线上环境.这就引起了git泄露漏洞. 打开靶机环境 查看网页内容 使用dirs ...

  9. linux7下修改主机名的方式

    在基于linux发行版的众多linux kernel 3.0以上,包括rhel7,centos7等提供多种修改linux主机名的方式 1.通过编辑/etc/hostname文件 2.命令hostnam ...

  10. 环境配置-Java-01-安装

    本文使用JDK1.8在windows64位系统下举例,其他版本在windows下的安装过程类似 0.百度云盘链接 考虑到官网下载需要登陆,这里给大家提供百度云盘链接(就是官网安装包),不过下载速度会比 ...