Codeforces Round 878 (Div. 3)

A:ABC

A. Cipher Shifer

题意:在自身后面添加一个字母,但是不能添加自身

思路:找到第二个与自身相符的就再找

#include <bits/stdc++.h>

using namespace std;
const int MAX = 110;
char a[MAX]; void solve() {
int n;
cin >> n;
for (int i = 0; i < n; i++) {
cin >> a[i];
}
int num = 0;
for (int i = 1; i < n; i++) {
if (a[num] == a[i]) {
cout << a[num];
num = ++i;
}
}
cout << "\n";
} int main() {
int t;
cin >> t;
while (t--) {
solve();
}
return 0;
}

B. Binary Cafe

题意:求一个数n用<2^k的二进制数的表示方法

思路:每个数都有一个独立的二进制来表示,每个二进制表示都可记作一种方案(空集是一种单独的方案)int>1e9所以k>32直接输出n+1就行。其他的再判断就行

#include <bits/stdc++.h>

using namespace std;
#define int long long int qmi(int a, int b) {
int res = 1;
while (b) {
if (b & 1) {
res = res * a;
}
a *= a;
b >>= 1;
}
return res;
} void solve() {
int n, k;
cin >> n >> k;
if (k >= 32) {
cout << n + 1 << "\n";
} else {
int res = qmi(2, k) - 1;
if (res > n) cout << n + 1 << "\n";
else {
cout << res + 1 << "\n";
}
}
} signed main() {
int t;
cin >> t;
while (t--) {
solve();
}
return 0;
}

C. Ski Resort

题意:一共n天,要连续去k天,这k天中a[i]<=q

思路:用一个记录有多少天连续满足这个条件,然后如果cnt>=k那么急可以在这几天去

#include <bits/stdc++.h>

using namespace std;
#define int long long
const int MAX = 2e5 + 10;
bool t[MAX];
int dp[MAX]; void solve() {
int n, k, q;
cin >> n >> k >> q;
for (int i = 1; i <= n; i++) {
int x;
cin >> x;
if (x <= q) {
t[i] = true;
} else t[i] = false;
}
int cnt = 0;
for (int i = 1; i <= n; i++) {
if (t[i]) cnt++;
else cnt = 0;
dp[i] = dp[i - 1];
if (cnt >= k) {
dp[i] += cnt - k + 1;
}
}
cout << dp[n] << "\n"; } signed main() {
int t;
cin >> t;
while (t--) {
solve();
}
return 0;
}

D. Wooden Toy Festival

题意:有x,y,z三个数,要让abs(a[i]-x)+abs(a[i]-y)+abs(a[i]-z)最小

思路:二分答案,是否有满足大于当前二分答案的两倍的个数大于3(大致分成三份),如果有就在大于当前二分的值的区间,否则就左边找

#include <bits/stdc++.h>

using namespace std;
#define int long long
const int MAX = 2e5 + 10;
int a[MAX];
int n; bool check(int k) {
int num = 0;
int x = a[1];
for (int i = 1; i <= n; i++)
if (abs(a[i] - x) > k * 2) {
x = a[i];
num++;
}
if (num >= 3) return false;
return true;
} void solve() {
cin >> n;
for (int i = 1; i <= n; i++) {
cin >> a[i];
}
if (n <= 3) {
cout << "0" << endl;
return;
}
sort(a + 1, a + n + 1);
int l = 0, r = a[n];
int mid;
while (l <= r) {
mid = (l + r) >> 1;
if (check(mid)) r = mid - 1;
else l = mid + 1;
}
cout << l << "\n";
} signed main() {
int t;
cin >> t;
while (t--) {
solve();
}
return 0;
}

E. Character Blocking

总结:大致思路有,但是没想到用map来存麻痹时间,题刷少了

题意:有三种操作:1.在 t 秒内屏蔽两个字符串中位于 pos位置的字符

2.交换两个未屏蔽的字符(注:不一定是不同字符串的)

3.确定两个字符在查询是是否相等

思路:找一个cnt确定有几个数是坏(没被屏蔽并且不相等),用map来储存屏蔽时间

#include <bits/stdc++.h>

using namespace std;

void solve() {
string a, b;
cin >> a >> b;
a = " " + a;
b = " " + b;
int t, m;
cin >> t >> m;
int cnt = 0;
map<int, vector<int>> mp;
for (int i = 1; i < a.size(); i++) {
cnt += a[i] != b[i];
}
for (int i = 1; i <= m; i++) {//屏蔽时间问题
for (auto &x: mp[i]) {
if (a[x] != b[x]) cnt++;
}
int op;
cin >> op;
if (op == 1) {
int x;
cin >> x;
cnt -= (a[x] != b[x]);
mp[i + t].push_back(x);//i+t是解除屏蔽的时间
} else if (op == 2) {
int x1, y1, x2, y2;
cin >> x1 >> y1 >> x2 >> y2;
if (x1 == 1 && x2 == 1) {
if (a[y1] != b[y1]) cnt--;
if (a[y2] != b[y2]) cnt--;
swap(a[y1], a[y2]);
if (a[y1] != b[y1]) cnt++;
if (a[y2] != b[y2]) cnt++;
} else if (x1 == 1 && x2 == 2) {
if (a[y1] != b[y1]) cnt--;
if (a[y2] != b[y2]) cnt--;
swap(a[y1], b[y2]);
if (a[y1] != b[y1]) cnt++;
if (a[y2] != b[y2]) cnt++;
} else if (x1 == 2 && x2 == 1) {
if (b[y1] != a[y1]) cnt--;
if (b[y2] != a[y2]) cnt--;
swap(b[y1], a[y2]);
if (b[y1] != a[y1]) cnt++;
if (b[y2] != a[y2]) cnt++;
} else if (x1 == 2 && x2 == 2) {
if (b[y1] != a[y1]) cnt--;
if (b[y2] != a[y2]) cnt--;
swap(b[y1], b[y2]);
if (b[y1] != a[y1]) cnt++;
if (b[y2] != a[y2]) cnt++;
}
} else {
if (cnt) cout << "NO\n";
else cout << "YES\n";
}
}
} int main() {
int t;
cin >> t;
while (t--) {
solve();
}
return 0;
}

Codeforces Round 878 (Div. 3)的更多相关文章

  1. Codeforces Round #443 (Div. 2) 【A、B、C、D】

    Codeforces Round #443 (Div. 2) codeforces 879 A. Borya's Diagnosis[水题] #include<cstdio> #inclu ...

  2. Codeforces Round #366 (Div. 2) ABC

    Codeforces Round #366 (Div. 2) A I hate that I love that I hate it水题 #I hate that I love that I hate ...

  3. Codeforces Round #354 (Div. 2) ABCD

    Codeforces Round #354 (Div. 2) Problems     # Name     A Nicholas and Permutation standard input/out ...

  4. Codeforces Round #368 (Div. 2)

    直达–>Codeforces Round #368 (Div. 2) A Brain’s Photos 给你一个NxM的矩阵,一个字母代表一种颜色,如果有”C”,”M”,”Y”三种中任意一种就输 ...

  5. cf之路,1,Codeforces Round #345 (Div. 2)

     cf之路,1,Codeforces Round #345 (Div. 2) ps:昨天第一次参加cf比赛,比赛之前为了熟悉下cf比赛题目的难度.所以做了round#345连试试水的深浅.....   ...

  6. Codeforces Round #279 (Div. 2) ABCDE

    Codeforces Round #279 (Div. 2) 做得我都变绿了! Problems     # Name     A Team Olympiad standard input/outpu ...

  7. Codeforces Round #262 (Div. 2) 1003

    Codeforces Round #262 (Div. 2) 1003 C. Present time limit per test 2 seconds memory limit per test 2 ...

  8. Codeforces Round #262 (Div. 2) 1004

    Codeforces Round #262 (Div. 2) 1004 D. Little Victor and Set time limit per test 1 second memory lim ...

  9. Codeforces Round #371 (Div. 1)

    A: 题目大意: 在一个multiset中要求支持3种操作: 1.增加一个数 2.删去一个数 3.给出一个01序列,问multiset中有多少这样的数,把它的十进制表示中的奇数改成1,偶数改成0后和给 ...

  10. Codeforces Round #268 (Div. 2) ABCD

    CF469 Codeforces Round #268 (Div. 2) http://codeforces.com/contest/469 开学了,时间少,水题就不写题解了,不水的题也不写这么详细了 ...

随机推荐

  1. 从浅入深了解.NET Core MVC 2.x全面教程

    一.基础 1.默认配置 使用Kestrel Web Server ASP.NET Core内置--跨平台 IIS集成 UseIIS() UseIISIntergration() Log IConfig ...

  2. 手工搭建并配置apache,php,mysql环境服务器

    1,安装apache2.4: 从apache官网中下载windows版本的apache二进制文件,解压 打开apache目录中的bin目录,在其中打开cmd窗口,使用命令: httpd -k inst ...

  3. RR有幻读问题吗?MVCC能否解决幻读?

    幻读是 MySQL 中一个非常普遍,且面试中经常被问到的问题,如果你还搞不懂什么是幻读?什么是 MVCC?以及 MySQL 中的锁?那么请好好收藏和阅读本篇文章,因为它非常重要. RR 隔离级别 在 ...

  4. 【Unity3D】高斯模糊特效

    1 高斯模糊原理 ​ 边缘检测特效中使用了卷积运算进行了边缘检测,本文实现的高斯模糊特效同样使用了卷积运算,关于卷积核和卷积运算的概念,读者可以参考边缘检测特效. ​ 本文完整资源见→Unity3D高 ...

  5. 知识图谱(Knowledge Graph)根本概念

    目录 知识图谱 定义 基础概念: 知识图谱构建的关键技术 知识图谱的构建 实体命名识别 知识抽取 实体统一 指代消解 知识图谱的存储 RDF和图数据库的主要特点区别 知识图谱能干什么 反欺诈 不一致性 ...

  6. java与es8实战之一:以builder pattern开篇

    欢迎访问我的GitHub 这里分类和汇总了欣宸的全部原创(含配套源码):https://github.com/zq2599/blog_demos 关于<java与es8实战>系列 < ...

  7. Airtest遇到模拟器无法输入中文的情况该如何处理?

    此文章来源于项目官方公众号:"AirtestProject" 版权声明:允许转载,但转载必须保留原链接:请勿用作商业或者非法用途 1. 前言 最近有收到同学们的一些提问,使用Air ...

  8. 《SQL与数据库基础》02. SQL-DDL

    目录 DDL 库管理 表管理 本文以 MySQL 为例 DDL 库管理 查看有哪些数据库: SHOW DATABASES; 使用某个数据库: USE 数据库名; 查看当前使用的数据库: SELECT ...

  9. shopee的前景以及商用API(代码封装)

    Shopee平台是东南亚和台湾地区最具代表性的电商平台之一,在过去几年里取得了巨大的成功.以下是Shopee平台的发展前景: 电商市场的快速增长:东南亚和台湾地区是人口众多.市场潜力巨大的区域,电商市 ...

  10. Dami 本地过程调用框架(主打解耦),v0.24 发布

    Dami,专为本地多模块之间通讯解耦而设计(尤其是未知模块.隔离模块.领域模块).零依赖,特适合 DDD. 特点 结合 Bus 与 RPC 的概念,可作事件分发,可作接口调用,可作异步响应. 支持事务 ...