补题链接:Here

1529A. Eshag Loves Big Arrays

【题意描述】

给定一个长度为 \(n\) 的正整数数组 \(a\) ,现在可执行若干次操作(可为 \(0\))

具体操作为:选定某个序列,删除严格大于序列的平均数的元素

请问最多能删去多少个元素

【解题思路】

观察一下样例容易发现,在若干次操作之后,一定是最小的元素留下,所以我们只需要统计最小值元素个数,然后输出 \(n - Mincnt\)

【AC 代码】

void solve() {
int n;
cin >> n;
int a[n + 1];
for (int i = 1; i <= n; ++i)cin >> a[i];
sort(a + 1, a + 1 + n);
int cnt = 0;
for (int i = 1; i <= n; ++i)if (a[i] == a[1])cnt++;
cout << n - cnt << "\n";
}

1529B. Sifid and Strange Subsequences

【题意描述】

先有一个长度为 \(n\) 的数组,定义“奇怪数组”:数组中任意两个元素的绝对值差值大于等于数组中的最大值,即 \(|a_i - a_j| >= Max\) ,请问由原数组中最大能选出多少个元素构成“奇怪数组”

【解题思路】

很容易证明一个奇怪的子序列不能包含一个以上的正元素。

所以最好选择所有的非正元素,现在我们最多只能选择一个正元素。

假设x是数组中最小的正元素。如果已经选取的集合中没有两个元素(如a和b)以a的方式存在,我们可以选取 \(|x−b |<x\)。

要检查这一点,我们只需对已经拾取的元素进行排序,并查看相邻元素对之间的差异。

复杂性:\(\mathcal{O}(nlog\ n)\)

【AC 代码】

void solve() {
int n;
cin >> n;
vector<int>a(n);
for (int &x : a)cin >> x;
sort(a.begin(), a.end());
int ans = 0, cnt0 = 0, cnt = 0;
for (int i = 0; i < n; ++i) {
if (a[i] < 0)ans++;
else if (a[i] == 0)cnt0++;
}
int res = ans + cnt0, Min = 1e9;
for (int i = 0; i + 1 < n; ++i) {
if (a[i + 1] > 0)break;
Min = min(Min, a[i + 1] - a[i]);
}
for (int i = 0; i < n; ++i)if (a[i] > 0 and a[i] <= Min)cnt++;
res = max(res, ans + (cnt0 > 0) + (cnt > 0));
cout << res << "\n";
}

1529C. Parsa's Humongous Tree

【题意描述】

给你一棵树,树上的每个节点 \(i\) 都有一个值域 \([l_i,r_i]\) ,我们需要从值域中确定一个值 \(a_i \in [l_i,r_i]\) ,而 \((u,v)\) 边权值则为$∣a_u − a_v∣ $ 。我们的目的就是要让所有的边权值之和最大。求出最大权值之和。

【解题思路】

感觉AtCoder上有一道很像的题

【AC 代码】

using ll = long long;
const int N = 1e5 + 10;
vector<int>g[N];
int a[N][2], n;
ll f[N][2];
void dfs(int v, int p) {
for (int s : g[v])
if (s != p) {
dfs(s, v);
f[v][0] += max(f[s][0] + abs(a[s][0] - a[v][0]), f[s][1] + abs(a[s][1] - a[v][0]));
f[v][1] += max(f[s][0] + abs(a[s][0] - a[v][1]), f[s][1] + abs(a[s][1] - a[v][1]));
}
}
void solve() {
cin >> n;
for (int i = 0; i < n; ++i)cin >> a[i][0] >> a[i][1];
for (int i = 0, u, v; i + 1 < n; ++i) {
cin >> u >> v;
--u, --v;
g[u].push_back(v);
g[v].push_back(u);
}
dfs(0, -1);
cout << max(f[0][0], f[0][1]) << "\n";
for (int i = 0; i < n; ++i) {
g[i].clear();
f[i][0] = f[i][1] = 0;
}
}

1529D. Kavi on Pairing Duty

【题意描述】

【解题思路】

设 \(dp_i\) 为 \(2i\) 点的良好配对数。

显然,答案是 \(dp_n\) 。

引理:表示x为与点1匹配的点。注意每个点p(\(x<p≤2n\) )属于长度等于 \([1,x]\) 长度的线段。

证明:假设某点p(\(x<p≤2n\) )与点q配对(q>p),因为[p,q]不在 \([1,x]\) 之内,所以它们的大小必须相等,配对才是好的。

为了计算dpn,考虑以下情况:

  • \(x>n\) :类似于上述引理,可以证明每个点p(\(1≤p≤2n−x+1\))与点i+x配对−1,剩余的未配对x−n−1个点形成一个连续的子阵列,该子阵列位于每个当前对内,因此它们可以在dpx中配对−n−1种方式。
  • \(x≤n\):在这种情况下,由于上述引理,所有的线段必须具有相同的长度,因此它们的长度必须是n的一个除数,在这种情况下,它们可以以D(n)的方式配对;其中D(n)是n的除数。

所以 \(dp_n=D(n)+∑^{n−1}_{i=0}dp_i\)。

注意 \(dp_0=dp_1=1\)。

【AC 代码】

const int N = 1e6 + 10, MOD = 998244353;
int n, dp[N], S;
void solve() {
cin >> n;
for (int i = 1; i <= n; i++) {
for (int j = i + i; j <= n; j += i) {
dp[j]++;
}
}
dp[0] = S = 1;
for (int i = 1; i <= n; i++) {
dp[i] = (dp[i] + S) % MOD;
S = (S + dp[i]) % MOD;
}
cout << dp[n] << endl;
}

Codeforces Round #722 (Div. 2) A~D题解的更多相关文章

  1. Codeforces Round #612 (Div. 2) 前四题题解

    这场比赛的出题人挺有意思,全部magic成了青色. 还有题目中的图片特别有趣. 晚上没打,开virtual contest打的,就会前三道,我太菜了. 最后看着题解补了第四道. 比赛传送门 A. An ...

  2. Codeforces Round #198 (Div. 2)A,B题解

    Codeforces Round #198 (Div. 2) 昨天看到奋斗群的群赛,好奇的去做了一下, 大概花了3个小时Ak,我大概可以退役了吧 那下面来稍微总结一下 A. The Wall Iahu ...

  3. Codeforces Round #672 (Div. 2) A - C1题解

    [Codeforces Round #672 (Div. 2) A - C1 ] 题目链接# A. Cubes Sorting 思路: " If Wheatley needs more th ...

  4. Codeforces Round #614 (Div. 2) A-E简要题解

    链接:https://codeforces.com/contest/1293 A. ConneR and the A.R.C. Markland-N 题意:略 思路:上下枚举1000次扫一遍,比较一下 ...

  5. Codeforces Round #610 (Div. 2) A-E简要题解

    contest链接: https://codeforces.com/contest/1282 A. Temporarily unavailable 题意: 给一个区间L,R通有网络,有个点x,在x+r ...

  6. Codeforces Round #611 (Div. 3) A-F简要题解

    contest链接:https://codeforces.com/contest/1283 A. Minutes Before the New Year 题意:给一个当前时间,输出离第二天差多少分钟 ...

  7. Codeforces Round #499 (Div. 2) D. Rocket题解

    题目: http://codeforces.com/contest/1011/problem/D This is an interactive problem. Natasha is going to ...

  8. Codeforces Round #499 (Div. 2) C Fly题解

    题目 http://codeforces.com/contest/1011/problem/C Natasha is going to fly on a rocket to Mars and retu ...

  9. Codeforces Round #198 (Div. 2)C,D题解

    接着是C,D的题解 C. Tourist Problem Iahub is a big fan of tourists. He wants to become a tourist himself, s ...

  10. Codeforces Round #579 (Div. 3) 套题 题解

    A. Circle of Students      题目:https://codeforces.com/contest/1203/problem/A 题意:一堆人坐成一个环,问能否按逆时针或者顺时针 ...

随机推荐

  1. 基于TensorFlow 2与PaddlePaddle 2预测泰坦尼克号旅客生存概率的比较

    ​  目录 1,程序比较 2,训练过程对比: 3,训练结果对比 AI框架经过大浪淘沙之后,目前真正能够完整用于生产.科研.学术的只剩下了谷歌.脸书.百度三家的框架,本文通过一个泰坦尼克号旅客生存概率预 ...

  2. 【UniApp】-uni-app-路由

    前言 好,经过上个章节的介绍完毕之后,了解了一下 uni-app-CompositionAPI应用生命周期和页面生命周期 那么了解完了uni-app-CompositionAPI应用生命周期和页面生命 ...

  3. 解决Tensorflow2.0出现:AttributeError: module 'tensorflow' has no attribute 'get_default_graph'的问题

    问题描述 在使用tensorflow2.0时,遇到了这个问题: AttributeError: module 'tensorflow' has no attribute 'get_default_gr ...

  4. SSM整合 tomcat报错: <严重 [RMI TCP Connection(22)-127.0.0.1] org.apache.catalina.core.StandardContext.startInternal 一个或多个筛选器启动失败。完整的详细信息将在相应的容器日志文件中找到>

    前提:学了一个暑假 从Javaweb -> mybits ->spring -> spring-mvc 打算跟着网上ssm整合项目做一个项目 在完成最后一步spring对spring ...

  5. 【docker】docker中装Redis集群

    一.搭建步骤 1.启动容器 #关闭防火墙 systemctl start docker 2.新建6个docker容器redis实例 docker run -d --name redis-node-1 ...

  6. WinRM服务应用及配置说明

    一.什么是winRM服务 1.1.winRM服务介绍 Windows远程管理(WinRM)服务是Windows Server 2003 R2以上版本中一种新式的方便远程管理的服务.通过WinRM服务, ...

  7. 建议收藏备查!MySQL 常见错误代码说明

    先给大家看几个实例的错误分析与解决方案. 1.ERROR 2002 (HY000): Can't connect to local MySQL server through socket '/data ...

  8. 使用Java 17中的record替代Lombok的部分功能

    在DD长期更新的Java新特性专栏中,已经介绍过Java 16中开始支持的新特性:record的使用. 之前只是做了介绍,但没有结合之前的编码习惯或规范来聊聊未来的应用变化.最近正好因为互相revie ...

  9. 聊一聊如何结合Microsoft.Extensions.DependenyInjection和Castle.Core

    .net下 aop的实现AspectCore+Microsoft.Extensions.DependenyInjection.Autofac+Castle .DoraInterception+Micr ...

  10. 通过 KernelUtil.dll 劫持 QQ / TIM 客户端 QQClientkey / QQKey 详细教程(附源码)

    前言 由于 QQ 9.7.20 版本后已经不能通过模拟网页快捷登录来截取 QQClientkey / QQKey,估计是针对访问的程序做了限制,然而经过多方面测试,诸多的地区.环境.机器也针对这种获取 ...