Codeforces Round #677 (Div. 3)【ABCDE】
比赛链接:https://codeforces.com/contest/1433
A. Boring Apartments
题解
模拟即可。
代码
#include <bits/stdc++.h>
using namespace std;
int main() {
ios::sync_with_stdio(false);
cin.tie(nullptr);
int t;
cin >> t;
while (t--) {
int n;
cin >> n;
int ans = 0;
for (int i = 1; i <= 9; i++) {
int num = 0;
for (int j = 0; j < 4; j++) {
num = num * 10 + i;
ans += to_string(num).size();
if (num == n) break;
}
if (num == n) break;
}
cout << ans << "\n";
}
return 0;
}
B. Yet Another Bookshelf
题解
每次可以选取最左或最右端的书本合并,所以答案即两两书本间的空隙个数。
代码
#include <bits/stdc++.h>
using namespace std;
int main() {
ios::sync_with_stdio(false);
cin.tie(nullptr);
int t;
cin >> t;
while (t--) {
int n;
cin >> n;
vector<int> pos;
for (int i = 0; i < n; i++) {
int x;
cin >> x;
if (x == 1) pos.push_back(i);
}
int ans = 0;
for (int i = 1; i < int(pos.size()); i++)
ans += pos[i] - pos[i - 1] - 1;
cout << ans << "\n";
}
return 0;
}
C. Dominant Piranha
题解
如果全为一个值,那么一定无解。否则,一定有一个最大值左右有一个值小于它,找到这个最大值即可。
代码
#include <bits/stdc++.h>
using namespace std;
int main() {
ios::sync_with_stdio(false);
cin.tie(nullptr);
int t;
cin >> t;
while (t--) {
int n;
cin >> n;
vector<int> a(n);
int mx = 0;
for (auto &x : a) cin >> x, mx = max(mx, x);
if (all_of(a.begin(), a.end(), [&](int x) { return x == mx; })) {
cout << -1 << "\n";
} else {
int ans = -1;
for (int i = 0; i < n; i++) {
if (a[i] == mx) {
if (i - 1 >= 0 and a[i - 1] < a[i]) {
ans = i;
break;
}
if (i + 1 < n and a[i + 1] < a[i]) {
ans = i;
break;
}
}
}
cout << ans + 1 << "\n";
}
}
return 0;
}
D. Districts Connection
题解
如果所有地区都属于一个组织,那么一定无解。
否则将第一个组织第一个地区和其他组织所有地区相连,将第一个组织其他地区和其他组织任意地区相连即可。
代码
#include <bits/stdc++.h>
using namespace std;
int main() {
ios::sync_with_stdio(false);
cin.tie(nullptr);
int t;
cin >> t;
while (t--) {
int n;
cin >> n;
vector<int> a(n);
for (auto &x : a) cin >> x;
if (all_of(a.begin(), a.end(), [&](int x) { return x == a[0]; })) {
cout << "NO" << "\n";
} else {
cout << "YES" << "\n";
map<int, vector<int>> mp;
for (int i = 0; i < n; i++) {
mp[a[i]].push_back(i);
}
vector<vector<int>> v;
for (auto [x, vec] : mp) {
v.emplace_back(vec);
}
for (int i = 1; i < int(v.size()); i++) {
for (auto j : v[i]) {
cout << v[0].front() + 1 << ' ' << j + 1 << "\n";
}
}
for (int i = 1; i < int(v[0].size()); i++) {
cout << v[1].front() + 1 << ' ' << v[0][i] + 1 << "\n";
}
}
}
return 0;
}
E. Two Round Dances
题解
将 \(n\) 个人均分为两组:\(\frac{C_n^{\frac{n}{2}}}{2}\)
\(\frac{n}{2}\) 个人围成一圈:\((\frac{n}{2}-1)!\)
答案即:\(\frac{C_n^{\frac{n}{2}}}{2} \times ({\frac{n}{2}}-1)! ^2\) ,化简得 \(\frac{2(n-1)!}{n}\) 。
代码
#include <bits/stdc++.h>
using namespace std;
int main() {
ios::sync_with_stdio(false);
cin.tie(nullptr);
int n;
cin >> n;
long long fac = 1;
for (int i = 1; i <= n - 1; i++) fac *= i;
cout << 2 * fac / n << "\n";
return 0;
}
Codeforces Round #677 (Div. 3)【ABCDE】的更多相关文章
- Codeforces Round #411 (Div. 2) 【ABCDE】
A. Fake NP 题意:给你l,r,让你输出[l,r]里面除1以外的,出现因子数量最多的那个数. 题解:如果l==r输出l,否则都输出2 #include<bits/stdc++.h> ...
- Codeforces Round #382 Div. 2【数论】
C. Tennis Championship(递推,斐波那契) 题意:n个人比赛,淘汰制,要求进行比赛双方的胜场数之差小于等于1.问冠军最多能打多少场比赛.题解:因为n太大,感觉是个构造.写写小数据, ...
- Codeforces Round #684 (Div. 2)【ABC1C2】
比赛链接:https://codeforces.com/contest/1440 A. Buy the String 题解 枚举字符串中 \(0\) 或 \(1\) 的个数即可. 代码 #includ ...
- Codeforces Round #682 (Div. 2)【ABCD】
比赛链接:https://codeforces.com/contest/1438 A. Specific Tastes of Andre 题意 构造一个任意连续子数组元素之和为子数组长度倍数的数组. ...
- Codeforces Round #678 (Div. 2)【ABCD】
比赛链接:https://codeforces.com/contest/1436 A. Reorder 题解 模拟一下这个二重循环发现每个位置数最终都只加了一次. 代码 #include <bi ...
- Codeforces Round #676 (Div. 2)【ABCD】
比赛链接:https://codeforces.com/contest/1421 A. XORwice 题意 给出两个正整数 \(a.b\),计算 \((a \oplus x) + (b \oplus ...
- Codeforces Round #675 (Div. 2)【ABCD】
比赛链接:https://codeforces.com/contest/1422 A. Fence 题意 给出三条边 $a,b,c$,构造第四条边使得四者可以围成一个四边形. 题解 $d = max( ...
- Codeforces Round #668 (Div. 2)【ABCD】
比赛链接:https://codeforces.com/contest/1405 A. Permutation Forgery 题意 给出一个大小为 $n$ 的排列 $p$,定义 \begin{equ ...
- Codeforces Round #658 (Div. 2)【ABC2】
做完前四题还有一个半小时... 比赛链接:https://codeforces.com/contest/1382 A. Common Subsequence 题意 给出两个数组,找出二者最短的公共子序 ...
随机推荐
- CentOS7上安装jdk,mysql
最近笔者的云服务器由于中毒,重装系统了... 所以就记录下所有服务的搭建过程吧 1.安装jdk 在oracle上下载linux系统的jdk,笔者这里使用的是1.8 https://www.oracle ...
- Head First 设计模式 —— 09. 模版方法 (Template Method) 模式
模板方法模式 在一个方法中定义一个算法的骨架,而将一些步骤延迟到子类中.模板方法使得子类可以在不改变算法结构的情况下,重新定义算法中的某些步骤. P289 特点 主导算法框架,并且保护这个算法 P28 ...
- MySQL多版本并发控制——MVCC机制分析
MVCC,即多版本并发控制(Multi-Version Concurrency Control)指的是,通过版本链维护一个数据的多个版本,使得读写操作没有冲突,可保证不同事务读写.写读操作并发执行,提 ...
- 怎么判断innodb 日志缓冲区该设置为多大呢
怎么判断innodb 日志缓冲区该设置为多大呢
- QPinter 常用绘制图像的方法
阅读本文大概需要 3 分钟 我们在开发软件的过程中,绘制图像功能必不可少,使用 Qt 绘制图像时非常简单,只需要传递几个参数就可以实现功能,在 Qt 中绘制图像的 api有好几个 void drawI ...
- 容器编排系统K8s之包管理器Helm基础使用
前文我们了解了k8s上的hpa资源的使用,回顾请参考:https://www.cnblogs.com/qiuhom-1874/p/14293237.html:今天我们来聊一下k8s包管理器helm的相 ...
- 通过电脑浏览器调试真机h5兼容问题
前言 在h5开发过程中,起初我们使用PC浏览器的手机模式打开开发中的页面,并使用控制台进行调试,但实际真机兼容性问题无法调试到:在这种情况下,我们通常使用vConsole(即移动端的控制台)来调试,但 ...
- Python+Selenium+Unittest实现PO模式web自动化框架(1)
1.什么是PO模式? PO是Page Object的缩写 PO模式是自动化测试项目开发实践的最佳设计模式之一,讲页面定位和业务操作分开,也就是把对象的定位和测试脚本分开,从而提供可维护性. 主要有以下 ...
- c++hook内联汇编模板
1 #include "Windows.h" 2 #include "tlhelp32.h" 3 #include "String.h" 4 ...
- 初识JavaScript和jQuery
JavaScript 1.特性 ①脚本语言.JavaScript是一种解释型的脚本语言,C.C++.Java等语言先编译后执行, 而JavaScript是在程序的运行过程中逐行进行解释. ②基于对象. ...