比赛链接: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】的更多相关文章

  1. Codeforces Round #411 (Div. 2) 【ABCDE】

    A. Fake NP 题意:给你l,r,让你输出[l,r]里面除1以外的,出现因子数量最多的那个数. 题解:如果l==r输出l,否则都输出2 #include<bits/stdc++.h> ...

  2. Codeforces Round #382 Div. 2【数论】

    C. Tennis Championship(递推,斐波那契) 题意:n个人比赛,淘汰制,要求进行比赛双方的胜场数之差小于等于1.问冠军最多能打多少场比赛.题解:因为n太大,感觉是个构造.写写小数据, ...

  3. Codeforces Round #684 (Div. 2)【ABC1C2】

    比赛链接:https://codeforces.com/contest/1440 A. Buy the String 题解 枚举字符串中 \(0\) 或 \(1\) 的个数即可. 代码 #includ ...

  4. Codeforces Round #682 (Div. 2)【ABCD】

    比赛链接:https://codeforces.com/contest/1438 A. Specific Tastes of Andre 题意 构造一个任意连续子数组元素之和为子数组长度倍数的数组. ...

  5. Codeforces Round #678 (Div. 2)【ABCD】

    比赛链接:https://codeforces.com/contest/1436 A. Reorder 题解 模拟一下这个二重循环发现每个位置数最终都只加了一次. 代码 #include <bi ...

  6. Codeforces Round #676 (Div. 2)【ABCD】

    比赛链接:https://codeforces.com/contest/1421 A. XORwice 题意 给出两个正整数 \(a.b\),计算 \((a \oplus x) + (b \oplus ...

  7. Codeforces Round #675 (Div. 2)【ABCD】

    比赛链接:https://codeforces.com/contest/1422 A. Fence 题意 给出三条边 $a,b,c$,构造第四条边使得四者可以围成一个四边形. 题解 $d = max( ...

  8. Codeforces Round #668 (Div. 2)【ABCD】

    比赛链接:https://codeforces.com/contest/1405 A. Permutation Forgery 题意 给出一个大小为 $n$ 的排列 $p$,定义 \begin{equ ...

  9. Codeforces Round #658 (Div. 2)【ABC2】

    做完前四题还有一个半小时... 比赛链接:https://codeforces.com/contest/1382 A. Common Subsequence 题意 给出两个数组,找出二者最短的公共子序 ...

随机推荐

  1. 解决surfacebook无法运行64位虚拟机的问题

    如果您嫌烦请直接看英文部分解决方案,另外windows专业版内置的hyper-v也是一款及其好用的虚拟机. 网上各种方案都尝试过,但是每次使用VMware创建64为虚拟机的时候总会显示不支持64位虚拟 ...

  2. .NET 云原生架构师训练营(模块二 基础巩固 RabbitMQ Masstransit 详解)--学习笔记

    2.6.7 RabbitMQ -- Masstransit 详解 Consumer 消费者 Producer 生产者 Request-Response 请求-响应 Consumer 消费者 在 Mas ...

  3. 如果数据库上的row格式是mixed或者mixed的格式,如何对比两台数据库服务器上的数据是否一致呢

    如果数据库上的row格式是mixed或者mixed的格式,如何对比两台数据库服务器上的数据是否一致呢

  4. nodejs中使用worker_threads来创建新的线程

    目录 简介 worker_threads isMainThread MessageChannel parentPort和MessagePort markAsUntransferable SHARE_E ...

  5. Netty的简单Demo

    这个demo是通过网上下载: 使用maven构建的: 项目结构: pom.xml: <dependencies> <dependency> <groupId>io. ...

  6. IDEA安装codota插件和使用,开发人员的知心伙伴

    打开IDEA 点击左上角的File之后,如下图 成功后如图所示

  7. 镍氢可充电电池2.4V转3.3V,2V转3.3V稳压供电输出电路图

    PW5100可以实现2.4V转3.3V,2V转3.3V的稳压电源电路,输出电流500MA.静态电流10uA,SOT23-5封装.输出纹波低,轻载性能高(轻载电感推荐6.8UH-10UH). PW510 ...

  8. Navicat linux 官方最新版安装破解

    我们直接去官网下载linux版navicat 下载好之后执行命令打开软件 chmod +x navicat15-premium-cs.AppImage ./navicat15-premium-cs.A ...

  9. kubernetes 核心技术-Controller 控制器

    一.什么是Controller? Controller是在集群上管理和运行容器的对象,Controller是实际存在的,Pod是抽象的,主要创建管理pod 二.Pod和Controller的关系 Po ...

  10. Flask源码关于local的实现

    flask源码关于local的实现 try: # 协程 from greenlet import getcurrent as get_ident except ImportError: try: fr ...