Codeforces Round #728 (Div. 2) A~C 补题记录
比赛链接: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 补题记录的更多相关文章
- Codeforces Round #524 (Div. 2)(前三题题解)
这场比赛手速场+数学场,像我这样读题都读不大懂的蒟蒻表示呵呵呵. 第四题搞了半天,大概想出来了,但来不及(中途家里网炸了)查错,于是我交了两次丢了100分.幸亏这次没有掉rating. 比赛传送门:h ...
- Codeforces Round #426 (Div. 2)A B C题+赛后小结
最近比赛有点多,可是好像每场比赛都是被虐,单纯磨砺心态的作用.最近讲的内容也有点多,即便是点到为止很浅显的版块,刷了专题之后的状态还是~"咦,能做,可是并没有把握能A啊".每场网络 ...
- Codeforces Round #728 (Div. 2) C. Great Graphs
Great Graphs 题意 给你一个数组\(d\),\(d[i]\)表示从节点\(1\)到其他各个节点的最短路的长度,然后你可以对这个图进行加边(可以是负边),但不允许存在一个权值和为负数的回路. ...
- Codeforces Round #243 (Div. 2) B(思维模拟题)
http://codeforces.com/contest/426/problem/B B. Sereja and Mirroring time limit per test 1 second mem ...
- Codeforces Round #340 (Div. 2) B. Chocolate 水题
B. Chocolate 题目连接: http://www.codeforces.com/contest/617/problem/D Descriptionww.co Bob loves everyt ...
- Codeforces Round #340 (Div. 2) A. Elephant 水题
A. Elephant 题目连接: http://www.codeforces.com/contest/617/problem/A Descriptionww.co An elephant decid ...
- Codeforces Round #340 (Div. 2) D. Polyline 水题
D. Polyline 题目连接: http://www.codeforces.com/contest/617/problem/D Descriptionww.co There are three p ...
- Codeforces Round #338 (Div. 2) A. Bulbs 水题
A. Bulbs 题目连接: http://www.codeforces.com/contest/615/problem/A Description Vasya wants to turn on Ch ...
- 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 ...
- 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. Linux 软件介绍
重点: rpm -i -e -qi -ql -qf -qa --scripts. yum install remove info list repolist provides. 配置系统源. 搭建私有 ...
- 在EXCEL表格中快速自动求和
在Microsoft Excel中,可以通过多种方式快速自动求和.以下是一种简单但常用的方法: 使用SUM函数 选定求和区域: 在Excel表格中,首先需要选定要进行求和的区域.这可以是一个列.行或者 ...
- jmeter-json断言
1.JSON 断言所在位置:断言->JSON 断言 2.JSON断言中的字段解析 Assert JSON Path exists:json 表达式,判断所字段是否存在,存在则为True, 否则为 ...
- 吉特日化MES-业务架构第一版图
- 经典卷积神经网络LeNet&AlexNet&VGG
LeNet LeNet-5是一种经典的卷积神经网络结构,于1998年投入实际使用中.该网络最早应用于手写体字符识别应用中.普遍认为,卷积神经网络的出现开始于LeCun等提出的LeNet网络,可以说Le ...
- Educational Codeforces Round 160 (Rated for Div. 2) 题解A~D
Educational Codeforces Round 160 (Rated for Div. 2) A. Rating Increase 纯暴力,分割字符串,如果n1<n2就输出,如果遍历完 ...
- 【笔记整理】[案例]爱词霸翻译post请求
import json if __name__ == '__main__': import requests resp = requests.post( url="http://ifanyi ...
- 【C#】【IO】【实例】接上一个统计的新功能
先用Python来创建多层级文件夹: import os root_path = r"C:\Users\Desktop\文案整理\Practice" for item in ran ...
- 在WInform开发中实现工具栏/菜单的动态呈现
在Winform系统开发中,为了对系统的工具栏/菜单进行动态的控制,我们对系统的工具栏/菜单进行动态配置,这样可以把系统的功能弹性发挥到极致.通过动态工具栏/菜单的配置方式,我们可以很容易的为系统新增 ...
- java中获取内网IP
package com.dashan.utils.iputils; import org.apache.commons.lang.StringUtils; import javax.servlet.h ...