Codeforces Round #677 (Div. 3) 题解
Codeforces Round #677 (Div. 3) 题解
A. Boring Apartments
题目

题解
简单签到题,直接数,小于这个数的\(+10\)。
代码
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define IOS ios_base::sync_with_stdio(0); cin.tie(0);cout.tie(0);
const int maxn = 2e5 + 10;
int a[maxn];
void solve(){
    ll ans = 0;
    int n; cin >> n;
    int cnt = 0, x = n, c10 = 1;
    while(x){
        x /= 10;
        cnt++;
        c10 *= 10;
    }
    c10 /= 10;
    int t = n / c10;
    // cout << c10 << " " << cnt << " " << t << endl;
    ans += (t - 1) * 10;
    cout << ans + (1 + cnt) * cnt / 2 << endl;
}
int main(){
    IOS; int t; cin >> t;
    while(t--){
        solve();
    }
    return 0;
}
B. Yet Another Bookshelf(思维)
题目

题意
让书架上所有的书\((a[i] = 1)\) 相邻。每次可以将相邻的一段\(1\)(可以是\(1\)个)向左移或者右移。
题解
开始模拟了一遍,但没过,太菜了。
思路:统计每个\(1\)与其最近\(1\)之间有多少个\(0\)。
代码
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define IOS ios_base::sync_with_stdio(0); cin.tie(0);cout.tie(0);
const int maxn = 100 + 10;
int a[maxn], b[maxn];
void solve1(){
    int n; cin >> n;
    for (int i = 0; i < n; i++) cin >> a[i];
    vector<int> num;
    for (int i = 0; i < n; i++){
        if(a[i] == 0) num.push_back(0);
        if(a[i] == 1) {if(i == 0 || a[i-1] == 0) num.push_back(1); }
        // cout << i << " " << a[i] << " " << num.size() << endl;
    }
    // for (auto x : num) cout << x << " "; cout << endl;
    n = num.size();
    int cnt = 0, ans = 0x3f3f3f3f;
    for (int i = 0; i < n; i++) cnt += (num[i] & 1);
    if(cnt == 1){
        cout << 0 << endl;  return;
    }
    for (int l = 0; l + cnt - 1 < n; l++){
        int r = l + cnt - 1;
        int res = 0;
        vector<int> c0, c1;
        for (int i = 0; i < n; i++){
            if(i >= l && i <= r) {if(num[i] == 0) c0.push_back(i);}
            else {
                if(num[i] == 1) c1.push_back(i);
            }
        }
        for (int i = 0; i < c1.size(); i++){
            res += abs(c1[i] - c0[i]);
        }
        // cout << l << " " << r << " " << res << endl;
        ans = min(ans, res);
    }
    cout << ans << endl;
}
void solve(){
    int n; cin >> n;
    vector<int> num;
    for (int i = 0; i < n; i++){
        cin >> a[i];
        if(a[i]) num.push_back(i);
    }
    cout << num.back() - num[0] - 1 - num.size() + 2 << endl;
}
int main(){
    IOS; int t; cin >> t;
    while(t--){
        solve();
    }
    return 0;
}
C. Dominant Piranha(思维)
题目

题意
水族馆里的食人鱼每次可以吃掉比它小的相邻的食人鱼。求最后的那一个食人鱼最开始的位置。
题解
找最大值。(比B简单?)
代码
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define pi pair<int, int>
#define IOS ios_base::sync_with_stdio(0); cin.tie(0);cout.tie(0);
const int maxn = 3e5 + 10;
int a[maxn];
void solve(){
    int n; cin >> n;
    for (int i = 1; i <= n; i++) cin >> a[i];
    vector<pi> num;
    for (int i = 1; i <= n; i++){
        if(i > 1 && a[i] > a[i-1]) num.push_back({a[i], i});
        if(i < n && a[i] > a[i+1]) num.push_back({a[i], i});
    }
    int pos = -1;
    for (auto p : num){
        if(pos == -1) pos = p.second;
        else if(a[pos] < p.first) pos = p.second;
    }
    cout << (pos == -1 ? -1 : pos) << endl;
}
int main(){
    IOS; int t; cin >> t;
    while(t--){
        solve();
    }
    return 0;
}
D. Districts Connection(简单构造)
题目

题意
要在\(n\)个点建建立\(n-1\) 条边,使\(n\)个点联通(直接或者间接)。但是相同的帮派间不可以建边,构造出一个可行的方案。
题解
- 当只有\(1\)个帮派的时候,连接\(n\)个顶点是不可能的。 
- 我们可以选一个帮派,记为\(gang1\),将其中一个点和其他的每一个点连接。这样保证这个点与不是帮派\(gang1\)的所有的点联通。 再将帮派\(gang1\)的其他点与不在帮派\(gang1\)的任一点连接,这样构造保证所有的点互相联通。 
代码
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define IOS ios_base::sync_with_stdio(0); cin.tie(0);cout.tie(0);
const int maxn = 5e3 + 10;
int a[maxn];
void solve(){
    int n; cin >> n;
    unordered_map<int, vector<int>> p;
    for (int i = 0; i < n; i++){
        cin >> a[i];
        p[a[i]].push_back(i + 1);
    }
    if((int)p[a[0]].size() == n){
        cout << "NO" << endl;
        return;
    }
    cout << "YES" << endl;
    int pos = a[0];
    for(auto x : p){
        if(x.first == pos) continue;
        for(auto c : x.second) cout << 1 << " " << c << endl;
    }
    for(auto x : p){
        if(x.first != a[0]){
            pos = x.first;
            break;
        }
    }
    vector<int> t = p[a[0]];
    int q = p[pos][0];
    // cout << "at: " << pos << " " << t.size() << " " << q << endl;
    for (int i = 1; i < (int)t.size(); i++){
        cout << q << " " << t[i] << endl;
    }
}
int main(){
    IOS; int t; cin >> t;
    while(t--){
        solve();
    }
    return 0;
}
E. Two Round Dances
题目

题解
( 在oeis网上输入\(12164510040883200\) 就明白了。)
圆排列。
代码
#include <bits/stdc++.h>
using namespace std;
#define ll unsigned long long
#define IOS ios_base::sync_with_stdio(0); cin.tie(0);cout.tie(0);
const int maxn = 3e5 + 10;
int a[maxn], dp[maxn];
void solve(){
    int n; cin >> n;
    if(n <= 4){
        cout << (n == 2 ? 1 : 3) << endl;
        return;
    }
    n /= 2; n-=1;
    ll ans = 1;
    for (int i = 1; i <= 2 * n + 1; i++) if(i != n + 1) ans *= i;
    cout << ans << endl;
}
int main(){
    IOS; int t = 1;
    while(t--){
        solve();
    }
    return 0;
}
Codeforces Round #677 (Div. 3) 题解的更多相关文章
- Codeforces Round #182 (Div. 1)题解【ABCD】
		Codeforces Round #182 (Div. 1)题解 A题:Yaroslav and Sequence1 题意: 给你\(2*n+1\)个元素,你每次可以进行无数种操作,每次操作必须选择其 ... 
- Codeforces Round #608 (Div. 2) 题解
		目录 Codeforces Round #608 (Div. 2) 题解 前言 A. Suits 题意 做法 程序 B. Blocks 题意 做法 程序 C. Shawarma Tent 题意 做法 ... 
- Codeforces Round #525 (Div. 2)题解
		Codeforces Round #525 (Div. 2)题解 题解 CF1088A [Ehab and another construction problem] 依据题意枚举即可 # inclu ... 
- Codeforces Round #528 (Div. 2)题解
		Codeforces Round #528 (Div. 2)题解 A. Right-Left Cipher 很明显这道题按题意逆序解码即可 Code: # include <bits/stdc+ ... 
- Codeforces Round #466 (Div. 2) 题解940A 940B 940C 940D 940E 940F
		Codeforces Round #466 (Div. 2) 题解 A.Points on the line 题目大意: 给你一个数列,定义数列的权值为最大值减去最小值,问最少删除几个数,使得数列的权 ... 
- Codeforces Round #665 (Div. 2) 题解
		Codeforces Round #665 (Div. 2) 题解 写得有点晚了,估计都官方题解看完切掉了,没人看我的了qaq. 目录 Codeforces Round #665 (Div. 2) 题 ... 
- Codeforces Round #160 (Div. 1) 题解【ABCD】
		Codeforces Round #160 (Div. 1) A - Maxim and Discounts 题意 给你n个折扣,m个物品,每个折扣都可以使用无限次,每次你使用第i个折扣的时候,你必须 ... 
- Codeforces Round #383 (Div. 2) 题解【ABCDE】
		Codeforces Round #383 (Div. 2) A. Arpa's hard exam and Mehrdad's naive cheat 题意 求1378^n mod 10 题解 直接 ... 
- Codeforces Round #271 (Div. 2)题解【ABCDEF】
		Codeforces Round #271 (Div. 2) A - Keyboard 题意 给你一个字符串,问你这个字符串在键盘的位置往左边挪一位,或者往右边挪一位字符,这个字符串是什么样子 题解 ... 
随机推荐
- 【django】本地开发media用户上传文件访问路径找不到
			当我们在本地开发的时候,会碰到static可以访问,但是用户上传的文件设置在media下不可访问怎么办?settings配置: 接着在你的urls文件添加: from . import setting ... 
- Linux中的硬链接和软连接
			1.Linux链接概念Linux链接分两种,一种被称为硬链接(Hard Link),另一种被称为符号链接(Symbolic Link).默认情况下,ln命令产生硬链接. [硬连接]硬连接指通过索引节点 ... 
- OpenCV图像加载与保存
			OpenCV中的图像加载与保存 头文件是包含的库,在GitHub上下载的 imread("图片路径",图片加载方式) 图片加载方式: IMREAD_GRAYSCALE 灰度图像 I ... 
- 远程触发Jenkins的Pipeline任务的并发问题处理
			前文概述 本文是<远程触发Jenkins的pipeline任务>的续篇,上一篇文章实战了如何通过Http请求远程触发指定的Jenkins任务,并且将参数传递给Jenkins任务去使用,文末 ... 
- 解决mvn clean install的报错The packaging for this project did not assign a file to the build artifact
			解决mvn clean install的报错The packaging for this project did not assign a file to the build artifact 
- HTTPS证书知识扫盲
			1. 前言 现在搞网站域名不加个HTTPS就显得不专业,特别在使用JWT进行认证的接口一定要加HTTPS为你的接口增加一层安全屏障.今天就来聊聊配置HTTPS的关键SSL证书,也被称为CA证书. 2. ... 
- 代码格式化工具:clang-format
			IDE: Visual Studio Code Language: C/C++ 格式化工具: clang-format 安装 vscode安装扩展C/C++,扩展程序将自动安装clang-format ... 
- day39 Pyhton 并发编程02
			一.内容回顾 并发和并行的区别 并发 宏观上是在同时运行的 微观上是一个一个顺序执行 同一时刻只有一个cpu在工作 并行 微观上就是同时执行的 同一时刻不止有一个cpu在工作 什么是进程 一个运行中的 ... 
- day19 Pyhton学习 递归函数
			# 函数的递归 : 在一个函数的内部调用它自己 # import sys # sys.setrecursionlimit(1000000) # 设置递归的最大深度 # 总结 # 1.递归函数的定义 : ... 
- C#使用RabbitMq队列(Sample,Work,Fanout,Direct等模式的简单使用)
			1:RabbitMQ是个啥?(专业术语参考自网络) RabbitMQ是实现了高级消息队列协议(AMQP)的开源消息代理软件(亦称面向消息的中间件). RabbitMQ服务器是用Erlang语言编写的, ... 
