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 开学了,时间少,水题就不写题解了,不水的题也不写这么详细了 ...
随机推荐
- 使用supervisor守护freeswitch进程
一.安装supervisor yum install -y epel-release yum install -y supervisor systemctl start supervisord sys ...
- Jmeter线程组间传递变量
做接口测试,上一个线程组(A线程组)提取的变量,需要传递给下一个线程组(B线程组)使用.故需要将A线程组内提取的变量设置为全局变量.实现如下: 1. json提取变量(A线程组) 通过json提取器, ...
- 纯前端导出word手写复杂表格,并还原成word。百分百还原表格。一文搞定前端表格导出为word
本次的需求是手写一个养老院老人生活能力评定表,并且要能够录入信息,最终导出 表格因为有七页所以代码很多,可以不用看表格模板的详细代码. 先贴上最终效果图 填写完导出之后 基本上实现了样式的百分百还原导 ...
- Graphviz入门
Graphviz可以用于状态机图的绘制 要绘制一张状态图,我们需要两个图形元素 结点,边 结点和边都有自己的属性 结点可以是圆.矩形.填充 边有粗细
- 云原生(docker jenkins k8s)docker篇
docker (1)架构 ● Docker_Host: ○ 安装Docker的主机 ● Docker Daemon: ○ 运行在Docker主机上的Docker后台进程 ● Client: ○ 操作D ...
- 「repost - from Quack」Matroid.md
拟阵?type=header 拟阵的定义与常见性质 & 拟阵交算法 拟阵的定义与常见性质 独立集系统和拟阵 定义独立集系统\(S=(E,\mathcal{I})\),\(E\)是基本元素的集合 ...
- Springboot简单功能示例-5 使用JWT进行授权认证
springboot-sample 介绍 springboot简单示例 跳转到发行版 查看发行版说明 软件架构(当前发行版使用) springboot hutool-all 非常好的常用java工具库 ...
- 聊聊基于Alink库的随机森林模型
概述 随机森林(Random Forest)是一种集成学习(Ensemble Learning)方法,通过构建多个决策树并汇总其预测结果来完成分类或回归任务.每棵决策树的构建过程中都引入了随机性,包括 ...
- 其它——Postman做接口测试
文章目录 一 介绍 二 下载安装 三 使用 四 批量接口测试(创建collections) 五 导出与导入同事的接口 5.1 导出 5.2 导入 一 介绍 在前后端分离开发时,后端工作人员完成系统接口 ...
- Capture Data.dmg
苹果apple mac 系统检测 日常分析 软件 https://gigafiles.apple.com/#/download 现有文件可供下载. 备注 Capture Data 9.9.0 Th ...