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. Shell 基本用法
重点: 条件测试. read. Shell 环境配置. case. for. find. xargs. gzip,bzip2,xz. tar. sed. 1)编程基础 Linus 说:Talk is ...
- class-dump 混淆加固、保护与优化原理
class-dump 混淆加固.保护与优化原理 进行逆向时,经常需要dump可执行文件的头文件,用以确定类信息和方法信息,为hook相关方法提供更加详细的数据.class-dump的主要用于检查存 ...
- 不要用第三方日志包了Microsoft.Extensions.Logging功能就很强大
在.NET中,Microsoft.Extensions.Logging是一个广泛使用的日志库,用于记录应用程序的日志信息.它提供了丰富的功能和灵活性,使开发人员能够轻松地记录各种类型的日志,并将其输出 ...
- SpringCore完整学习教程7,入门级别
本章可以说是完结,下一章可能讲kotlin+springboot 本章从第九章开始: 9. Creating Your Own Auto-configuration 如果您在开发共享库的公司工作,或者 ...
- [USACO2007NOVS] Cow Hurdles S
题目描述 Farmer John wants the cows to prepare for the county jumping competition, so Bessie and the gan ...
- [python]数据分析--数据清洗处理case1
数据预处理案例1 主要涉及pandas读取csv文件,缺失值和重复值处理,分组计数,字段类型转换 ,结果写入到Excel. 根据要求对CSV数据集进行处理要求如下: 保留数据关键信息:time.lat ...
- MybatisPlus属性自动填充
阿里巴巴开发规范,对于每一张表都因该有id(主键),createTime(创建时间),updateTime(修改时间)这三个字段 主键ID我们可以使用自增,或者雪花算法 创建时间修改时间我们可以使用数 ...
- 【scikit-learn基础】--『预处理』之 离散化
数据的预处理是数据分析,或者机器学习训练前的重要步骤.通过数据预处理,可以 提高数据质量,处理数据的缺失值.异常值和重复值等问题,增加数据的准确性和可靠性 整合不同数据,数据的来源和结构可能多种多样, ...
- Scrapy-redis组件,实现分布式爬虫
安装包 pip install -U scrapy-redis settings.py ##### Scrapy-Redis ##### ### Scrapy指定Redis 配置 ### # 其他默认 ...
- SSM整合 tomcat报错: <严重 [RMI TCP Connection(22)-127.0.0.1] org.apache.catalina.core.StandardContext.startInternal 一个或多个筛选器启动失败。完整的详细信息将在相应的容器日志文件中找到>
前提:学了一个暑假 从Javaweb -> mybits ->spring -> spring-mvc 打算跟着网上ssm整合项目做一个项目 在完成最后一步spring对spring ...