比赛链接: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. 京东广告研发近期入选国际顶会文章系列导读——CIKM 2023篇

    近年来,放眼业界广告推荐领域的算法获得了长足的发展,从几篇奠定基础的序列学习.大规模图学习.在线学习&增强学习.多模态推荐问题等起步,业内算法不断迭代发展并在学术和工业场景上取得不错的应用. ...

  2. 【WCH以太网接口系列芯片】基于CH395的组播应用

    ---------------------------------------------------------------------------------------------------- ...

  3. [ABC261Ex] Game on Graph

    Problem Statement We have a directed graph with \(N\) vertices and \(M\) edges. Edge \(i\) is direct ...

  4. MybatisPlus实现高效的多对多查询

    1.前置 事先声明一下代码中蕴含了大量的Stream和Lambda表达式操作,还不清楚的小伙伴可以去参考一下Java8新特性Stream流,而却我是用的是MybatisPlus这方面不清楚的也可以参考 ...

  5. .NET Conf China 2023 活动纪实 抢先看

    ​ 今天2023年12月16日.NET Conf China 2023举办的日子,北京昨天上午还在飘起雪花,到今天早上的天气就有了极大的改观,大清早就能看到外面徐徐升起的朝阳,这也预示着今天将是一个大 ...

  6. Kernel Memory 入门系列:Kernel Memory Service

    Kernel Memory 入门系列:Kernel Memory Service 在 Kernel Memory 的 GitHub 仓库中有一个单独的项目 Service , 用于提供独立的Kerne ...

  7. ios上架流程 详细通关教程 2021

    记录此文是源于以下需求 1.已有app store开发者账号 (公司账号$99),需上架至app store 2.有商城实体商品支付功能(会员等虚拟支付另说) 3.有硬件交互功能 注:建议预留一周上架 ...

  8. Kernel Memory 入门系列:文档的管理

    Kernel Memory 入门系列: 文档的管理 在Quick Start中我们了解到如何快速直接地上传文档.当时实际中,往往会面临更多的问题,例如文档如何更新,如何划定查询范围等等.这里我们将详细 ...

  9. PythonAnywhere 部署Flask项目

    一. 注册账号 官网:https://www.pythonanywhere.com/ 二. 将GitHub上的项目发送至PythonAnywhere 三.配置环境及运行 git clone https ...

  10. 从Bitcask存储模型谈超轻量级KV系统设计与实现

    Bitcask介绍 Bitcask是一种"基于日志结构的哈希表"(A Log-Structured Hash Table for Fast Key/Value Data) Bitc ...