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 题意 给出两个数组,找出二者最短的公共子序 ...
随机推荐
- uni-app阻止事件向父级冒泡
在官网找到的就只有这个方法,但是我放在app项目里并不支持,所以就想到vue的阻止事件冒泡的方法,现在分享,免得大家踩坑 <view class="parent" @ ...
- Manjaro Linux 5.9.11-3安装和配置全局截图工具FlameShot教程
背景说明 截图工具是日常适用频率较高的一种系统工具,在Linux下也有不少常用截图工具,如deepin-screenshot等,但是今天我们要介绍的是FlameShot--一款更加精致的Linux全局 ...
- Upload - Labs (下)
Pass - 11: 1.查看源代码,发现进行了一次对后缀名替换成空格,因此考虑双写绕过, 2.上传成功, 关键代码: $is_upload = false; $msg = null; if (iss ...
- MyBatis初级实战之六:一对多关联查询
欢迎访问我的GitHub https://github.com/zq2599/blog_demos 内容:所有原创文章分类汇总及配套源码,涉及Java.Docker.Kubernetes.DevOPS ...
- 1V升压5V和1.5V升压5V的集成电路芯片
1.5V和1V输入,要升压输出5V的集成电路芯片合适? 干电池标准电压是1.5V,放电电压后面在0.9V-1V左右,如果要选用干电池1.5V升压到5V的合适的芯片,需要满足低压1V或者0.9V更好的低 ...
- web框架的本质:
简单的web框架 web的应用本质其实就是socket服务器,用户所使用的浏览器就是一个cocket客户端,客户使用浏览器发送的请求会被服务接收,服务器会按照http协议的响应协议来回复请求,这样的网 ...
- Flink可靠性的基石-checkpoint机制详细解析
Checkpoint介绍 checkpoint机制是Flink可靠性的基石,可以保证Flink集群在某个算子因为某些原因(如 异常退出)出现故障时,能够将整个应用流图的状态恢复到故障之前的某一状态,保 ...
- 并发编程常用工具类(一) countDownLatch和cyclicBarrier的使用对比
1.CountDownLatch countDownLatch的作用是让一组线程等待其他线程完成工作以后在执行,相当于加强版的join(不懂可以百度一下join的用法),一般在初始 ...
- hive 时间相关的函数
yyyy-MM-dd与yyyyMMdd000000转换的三种方法 方法一:date_format(只支持yyyy-MM-dd -> yyyyMMdd000000) select date_for ...
- ospf-lite runs over tcp / udp port 8899.
draft-thomas-reed-ospf-lite-01 - ospf-lite https://tools.ietf.org/html/draft-thomas-reed-ospf-lite-0 ...