Codeforces Round 878 (Div. 3)
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)的更多相关文章
- Codeforces Round #443 (Div. 2) 【A、B、C、D】
Codeforces Round #443 (Div. 2) codeforces 879 A. Borya's Diagnosis[水题] #include<cstdio> #inclu ...
- 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 ...
- Codeforces Round #354 (Div. 2) ABCD
Codeforces Round #354 (Div. 2) Problems # Name A Nicholas and Permutation standard input/out ...
- Codeforces Round #368 (Div. 2)
直达–>Codeforces Round #368 (Div. 2) A Brain’s Photos 给你一个NxM的矩阵,一个字母代表一种颜色,如果有”C”,”M”,”Y”三种中任意一种就输 ...
- cf之路,1,Codeforces Round #345 (Div. 2)
cf之路,1,Codeforces Round #345 (Div. 2) ps:昨天第一次参加cf比赛,比赛之前为了熟悉下cf比赛题目的难度.所以做了round#345连试试水的深浅..... ...
- Codeforces Round #279 (Div. 2) ABCDE
Codeforces Round #279 (Div. 2) 做得我都变绿了! Problems # Name A Team Olympiad standard input/outpu ...
- 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 ...
- 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 ...
- Codeforces Round #371 (Div. 1)
A: 题目大意: 在一个multiset中要求支持3种操作: 1.增加一个数 2.删去一个数 3.给出一个01序列,问multiset中有多少这样的数,把它的十进制表示中的奇数改成1,偶数改成0后和给 ...
- Codeforces Round #268 (Div. 2) ABCD
CF469 Codeforces Round #268 (Div. 2) http://codeforces.com/contest/469 开学了,时间少,水题就不写题解了,不水的题也不写这么详细了 ...
随机推荐
- quarkus依赖注入之八:装饰器(Decorator)
欢迎访问我的GitHub 这里分类和汇总了欣宸的全部原创(含配套源码):https://github.com/zq2599/blog_demos 本篇概览 本篇是<quarkus依赖注入> ...
- AVR汇编(四):数据传送指令
AVR汇编(四):数据传送指令 AVR指令主要分为五类:算术和逻辑指令.分支指令.位操作指令.数据传送指令.MCU控制指令,今天我们先来认识其中最常用的数据传送指令. 汇编程序的编写.编译和调试 学习 ...
- docker 搭建php环境(踩坑经验!!)
本次安装的推荐配置: nginx 1.24.0 mysql 5.7.43 php 7.4.3-fpm redis 7.2.0 一.安装虚拟机 vm虚拟机需要4g内存,网络使用nat模式设置静态ip ...
- WPF学习 - 自定义窗体(二)
上一篇文章写了如何创建自定义窗体:使用 WindowChrome 或者 WindowStyle="None"这两种方式.本文将讲述如何设置窗体的效果(以阴影效果为例),以及在效果模 ...
- Code Llama:Llama 2 学会写代码了!
引言 Code Llama 是为代码类任务而生的一组最先进的.开放的 Llama 2 模型,我们很高兴能将其集成入 Hugging Face 生态系统!Code Llama 使用与 Llama 2 相 ...
- 请大家一定不要像我们公司这样打印log日志
前言 最近接手了公司另一个项目,熟悉业务和代码苦不堪言. 我接手一个新项目,有个习惯,就是看结构,看数据库,搜代码. 其中搜代码是我个人这些年不知不觉形成的癖好,我下面给大家展示下这个小癖好. 正文 ...
- Vue vs React:你需要知道的一切
Vue 和 React 是创建 JavaScript 网络应用程序最常用的两种工具.但我们该如何在两者之间做出选择呢?在本篇 Vue 与 React 的对比中,我们将尝试找出答案.我们将回顾每种工具的 ...
- 解决SpringBoot3.X中starter配置自动注入失效问题
在自定义 starter 项目时,如果组件无法被 @ComponentScan 扫描并且想自动注册到 IOC 中,在springboot2.7之前 我们会采用 spring,factories 方式, ...
- open与fopen的区别
1. 来源 从来源的角度看,两者能很好的区分开,这也是两者最显而易见的区别: open是UNIX系统调用函数(包括LINUX等),返回的是文件描述符(File Descriptor),它是文件在文件描 ...
- 基于TRE文章的非线性模型化线性方法
之前写过一篇有关TRE优化模型详解的博文: https://www.cnblogs.com/zoubilin/p/17270435.html 这篇文章里面的附录给出了非线性模型化线性的方式,具体内容如 ...