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 题意 给出两个数组,找出二者最短的公共子序 ...
随机推荐
- SpringBoot嵌入式Servlet容器
SpringBoot默认是将Tomcat作为嵌入式的servlet容器. 问题: 如何修改嵌入式的servlet容器? 1)在配置文件中设置对应的属性值 server.port=8081 # Tomc ...
- 【JS学习】var let const声明变量的异同点
[JS学习]var let const声明变量的异同点 前言: 本博客系列为学习后盾人js教程过程中的记录与产出,如果对你有帮助,欢迎关注,点赞,分享.不足之处也欢迎指正,作者会积极思考与改正. 总述 ...
- 【Oracle】查看oracle表空间大小及增加表空间的几种方法
在oracle中表空间是必不可少的.但是怎么查看表空间呢 简单的查看方式是: SQL> select tablespace_name from dba_tablespaces; 想要查看表空间对 ...
- ctfshow—web—web4
打开靶机 发现与web3很相似,测试文件包含未成功 此题有两种解决方法 一.日志注入 查看日志的默认目录,得到了日志文件 ?url=/var/log/nginx/access.log 进行日志注入 & ...
- JS中常用的工具类
一.日期工具类 /** * 日期时间工具类 * @type {{dateFormat}} */ var DateTime = function () { var patterns = { PATTER ...
- es_python_操作
获取es索引 https://www.itranslater.com/qa/details/2583886977221264384
- response返回特性
1. response 返回特性 r=requests.get("http://www.baidu.com")print(r.text) #打印返回正文print(r.status ...
- JAVA高并发集合详解
Queue(队列)主要是为了高并发准备的容器Deque:双端队列,可以反方向装或者取 最开始jdk1.0只有Vector和hashtable 默认所有方法都实现了synchronized锁,线程安全但 ...
- connection-backoff ConnectionBackoff Strategy 回退
grpc/connection-backoff.md at master · grpc/grpc https://github.com/grpc/grpc/blob/master/doc/connec ...
- Linux监控内核SNMP计数器
nstat命令和rtacct命令是一个简单的监视内核的SNMP计数器和网络接口状态的实用工具. 语法 nstat/rtacct (选项) 选项 -h:显示帮助信息: -V:显示指令版本信息: -z:显 ...