比赛链接:Here

1541A. Pretty Permutations

给定 \(1,2,3,4,...n\) 序列,让每一个数字都不处于原来的位置,但总的移动距离要最小


  • \(n\) 为偶数的情况 \(1,2,3,4 \to 2,1,4,3\)
  • \(n\) 为奇数的情况 \(1,2,3,4,5 \to 2,1,4,5,3\)

【AC Code】

int main() {
cin.tie(nullptr)->sync_with_stdio(false);
int a[110];
for (int i = 1; i <= 101; ++i)a[i] = i;
for (int i = 1; i <= 101; i += 2) swap(a[i], a[i + 1]);
int _; for (cin >> _; _--;) {
int n; cin >> n;
if (n & 1) {
for (int i = 1; i <= n - 2; ++i)
cout << a[i] << " ";
cout << n << " " << a[n - 1];
} else {
for (int i = 1; i <= n; ++i)
cout << a[i] << " ";
}
cout << '\n';
}
}

1541B. Pleasant Pairs

问有多少对数 \((i,j)\) 满足以下条件:

  • \(i < j\)
  • \(a_i * a_j = i + j\)

相同题型:ABC206 C - Swappable

枚举所有 \(a_i\) 的倍数加以判断

注意点:\(i \not = j\)

时间复杂度:\(\mathcal{O}(n·log(n))\)

【AC Code】

int main() {
cin.tie(nullptr)->sync_with_stdio(false);
int _; for (cin >> _; _--;) {
ll n; cin >> n;
vector<ll>a(n + 1);
for (int i = 1; i <= n; ++i)cin >> a[i];
ll cnt = 0;
for (int i = 1; i <= n; ++i)
for (int j = a[i] - i; j <= n; j += a[i]) {
if (j <= i) continue;
else if (a[i] * a[j] == i + j)cnt++;
}
cout << cnt << "\n";
}
}

1541C. Great Graphs

\(n\) 个点和 \(d\) 数组,表示第 \(i\) 个点到第一个点的最短距离。

现在需要进行加边,然后使得所有边权和最小(可加负边)


思路转自码尔泰

很明显其实, \(d[i]\) 其实可以排个序,对于最后结果并没有影响,之后我们可以考虑对于每个点,只建一条正向道路,使得满足题目条件,然后在满足题目条件的情况下尽可能多地建反向道路,这样可以减小总的边权和。

【AC Code】

int main() {
cin.tie(nullptr)->sync_with_stdio(false);
int _; for (cin >> _; _--;) {
int n; cin >> n;
vector<ll>d(n + 1), sum(n + 1);
for (int i = 1; i <= n; ++i)cin >> d[i];
ll b = 1e9 + 7;
sort(d.begin() + 1, d.end());
for (int i = 1; i <= n; ++i) sum[i] = sum[i - 1] + d[i];
ll ans = 0;
for (int i = 3; i <= n; ++i)
ans -= d[i] * (i - 2) - sum[i - 2];
cout << ans << "\n";
}
}

Codeforces Round #728 (Div. 2) A~C 补题记录的更多相关文章

  1. Codeforces Round #524 (Div. 2)(前三题题解)

    这场比赛手速场+数学场,像我这样读题都读不大懂的蒟蒻表示呵呵呵. 第四题搞了半天,大概想出来了,但来不及(中途家里网炸了)查错,于是我交了两次丢了100分.幸亏这次没有掉rating. 比赛传送门:h ...

  2. Codeforces Round #426 (Div. 2)A B C题+赛后小结

    最近比赛有点多,可是好像每场比赛都是被虐,单纯磨砺心态的作用.最近讲的内容也有点多,即便是点到为止很浅显的版块,刷了专题之后的状态还是~"咦,能做,可是并没有把握能A啊".每场网络 ...

  3. Codeforces Round #728 (Div. 2) C. Great Graphs

    Great Graphs 题意 给你一个数组\(d\),\(d[i]\)表示从节点\(1\)到其他各个节点的最短路的长度,然后你可以对这个图进行加边(可以是负边),但不允许存在一个权值和为负数的回路. ...

  4. Codeforces Round #243 (Div. 2) B(思维模拟题)

    http://codeforces.com/contest/426/problem/B B. Sereja and Mirroring time limit per test 1 second mem ...

  5. Codeforces Round #340 (Div. 2) B. Chocolate 水题

    B. Chocolate 题目连接: http://www.codeforces.com/contest/617/problem/D Descriptionww.co Bob loves everyt ...

  6. Codeforces Round #340 (Div. 2) A. Elephant 水题

    A. Elephant 题目连接: http://www.codeforces.com/contest/617/problem/A Descriptionww.co An elephant decid ...

  7. Codeforces Round #340 (Div. 2) D. Polyline 水题

    D. Polyline 题目连接: http://www.codeforces.com/contest/617/problem/D Descriptionww.co There are three p ...

  8. Codeforces Round #338 (Div. 2) A. Bulbs 水题

    A. Bulbs 题目连接: http://www.codeforces.com/contest/615/problem/A Description Vasya wants to turn on Ch ...

  9. Codeforces Round #185 (Div. 2) B. Archer 水题

    B. Archer Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/contest/312/problem/B D ...

  10. Codeforces Round #282 (Div. 1) A. Treasure 水题

    A. Treasure Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/contest/494/problem/A ...

随机推荐

  1. 配置postcss-pxtorem报:options has an unknown property 'plugins'

    闲聊: 小颖最近在坐大屏相关的项目,要写适配,之前用的:postcss-px2rem.px2rem-loader,和朋友闲聊呢他说他们也在写大屏,不过他们用的 postcss-pxtorem,在写另外 ...

  2. 一文带你掌握C语言的循环结构

    C语言循环结构详解 在C语言中,循环结构是一种重要的控制结构,它允许我们重复执行一段代码,以达到特定的目的.循环结构可以帮助我们简化重复性的任务,提高代码的效率.本篇文章将深入探讨C语言中的循环结构, ...

  3. 又有新框架上线了,测试、AI 通通有「GitHub 热点速览」

    本周热点之一可能就是 Apple 刚开源便获得 8k+ star 的机器学习框架 mlx,顺带官方开源的 mlx-example(示例仓)也在热门榜上有一席之位,据说它已经跑通了大模型 Llama 7 ...

  4. [ARC144E]GCD of Path Weights

    Problem Statement You are given a directed graph $G$ with $N$ vertices and $M$ edges. The vertices a ...

  5. [ABC264Ex] Perfect Binary Tree

    Problem Statement We have a rooted tree with $N$ vertices numbered $1,2,\dots,N$. The tree is rooted ...

  6. ClickHouse(19)ClickHouse集成Hive表引擎详细解析

    目录 Hive集成表引擎 创建表 使用示例 如何使用HDFS文件系统的本地缓存 查询 ORC 输入格式的Hive 表 在 Hive 中建表 在 ClickHouse 中建表 查询 Parquest 输 ...

  7. Asp.net core Webapi 如何执行定时任务?

    前言 在计算机系统中,定时执行一些后台任务是很常见的场景,比如定时发送邮件.备份数据等等. 那么,.NET 技术如何通过编程灵活地实现项目里复杂的自定义任务呢? 如果是 Windows 生态,通常来说 ...

  8. pytest框架学习-前置和后置setup和teardown

    前置和后置 (1)setup和teardown,方法级 写在类中 方法级,每个用例都会执行setup和teardown. 相当于setup_method和teardown_method (2)setu ...

  9. 使用dtd定义元素

  10. OpenCV计算机视觉学习(15)——浅谈图像处理的饱和运算和取模运算

    如果需要其他图像处理的文章及代码,请移步小编的GitHub地址 传送门:请点击我 如果点击有误:https://github.com/LeBron-Jian/ComputerVisionPractic ...