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. C# 中关于 T 泛型【C# 基础】

    〇.前言 C# 里面的泛型不仅可以使用泛型函数.泛型接口,也可以使用泛型类.泛型委托等等.在使用泛型的时候,它们会自行检测你传入参数的类型,因此它可以为我们省去大量的时间,不用一个个编写方法的重载.与 ...

  2. SpringBoot3文件管理

    目录 一.简介 二.工程搭建 1.工程结构 2.依赖管理 三.上传下载 1.配置管理 2.上传下载 四.Excel文件 1.Excel创建 2.Excel读取 3.解析监听 4.导入导出 五.参考源码 ...

  3. 联通光猫获取超级管理员密码,联通宽带逻辑ID 获取

    首先使用普通账户登录然后访问这个链接 http://192.168.1.1/backpresettings.conf 保存backpresettings.conf 打开文件就可以看到 cuadmin ...

  4. Python 潮流周刊#17:Excel 终于支持 Python 了、Meta 重磅开源新项目、Mojo 新得 1 亿美元融资

    你好,我是猫哥.这里每周分享优质的 Python.AI 及通用技术内容,大部分为英文.标题取自其中两则分享,不代表全部内容都是该主题,特此声明. 本周刊由 Python猫 出品,精心筛选国内外的 25 ...

  5. 每天一道面试题:Spring的Bean生命周期

    Spring的Bean生命周期包括以下步骤: 1.实例化(Instantiation):当Spring容器接收到创建Bean的请求时,它会先实例化Bean对象.这个过程可以通过构造函数.工厂方法或者反 ...

  6. 初露头角!Walrus入选服贸会“数智影响力”数字化转型创新案例

    9月5日,由北京市通信管理局.工业和信息化部新闻宣传中心联合主办的"企业数字化转型论坛"在2023中国国际服务贸易交易会期间召开,论坛以"数字化引领 高质量发展" ...

  7. Unity 游戏开发、03 基础篇 | C#初级编程

    C#初级编程 https://learn.u3d.cn/tutorial/beginner-gameplay-scripting 8 Update 和 FixedUpdate Update(不是按固定 ...

  8. 文心一言 VS 讯飞星火 VS chatgpt (94)-- 算法导论9.2 3题

    三.用go语言,给出 RANDOMIZED-SELECT的一个基于循环的版本. 文心一言: 在循环中实现 RANDOMIZED-SELECT 的一个版本可以如下所示.这个版本使用 Go 语言编写,利用 ...

  9. Solution -「YunoOI 2016」镜中的昆虫

    Description Link. 区间推平: 区间数颜色. Solution 考虑无修的情况,我们是采用维护每个数的 \(pre\) 来做的.具体一点就是对于每一个 \(a_{i}\) 维护 \(p ...

  10. Python 列表操作指南3

    示例,将新列表中的所有值设置为 'hello': newlist = ['hello' for x in fruits] 表达式还可以包含条件,不像筛选器那样,而是作为操纵结果的一种方式: 示例,返回 ...