Codeforces Round 878 (Div3)
B. Binary Cafe
\(1 \leq n,k \leq 10^9\)
题解:思维
- 考虑两种情况
- 第一种:钱足够多,每种咖啡都可以买的情况下,答案为\(2^k\)
- 第二种:钱不够多,因为任一面值的钱数都有唯一的二进制表达方式,所以答案为\(n + 1\)
- 所以我们不妨先判断一下\(2^k\)有没有超过\(10^9\),如果超过了说明钱一定不够多,否则答案为\(min(2^k,n+1)\)
#include <bits/stdc++.h>
#define Zeoy std::ios::sync_with_stdio(false), std::cin.tie(0), std::cout.tie(0)
#define all(x) (x).begin(), (x).end()
#define rson id << 1 | 1
#define lson id << 1
#define int long long
#define mpk make_pair
#define endl '\n'
using namespace std;
typedef unsigned long long ULL;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<double, double> pdd;
const int inf = 0x3f3f3f3f;
const ll INF = 0x3f3f3f3f3f3f3f3f;
const int mod = 1e9 + 7;
const double eps = 1e-9;
const int N = 2e5 + 10, M = 4e5 + 10;
void solve()
{
int n, k;
cin >> n >> k;
if (k >= 30)
{
cout << n + 1 << endl;
}
else
cout << min(n + 1, (1LL << k)) << endl;
}
signed main(void)
{
Zeoy;
int T = 1;
cin >> T;
while (T--)
{
solve();
}
return 0;
}
C. Ski Resort
题解:组合计数
- 我们不妨将连续的可以度假的时间看成一个线段
- 那么我们需要在这个线段中挑选连续的子线段作为一种方案
- 容易发现我们可以使用捆绑法后即可得到答案
- 假设线段长度为\(len\),且\(len >= k\),那么答案应该为\(\frac{(len - k + 1) \times (len - k + 2)}{2}\)
#include <bits/stdc++.h>
#define Zeoy std::ios::sync_with_stdio(false), std::cin.tie(0), std::cout.tie(0)
#define all(x) (x).begin(), (x).end()
#define rson id << 1 | 1
#define lson id << 1
#define int long long
#define mpk make_pair
#define endl '\n'
using namespace std;
typedef unsigned long long ULL;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<double, double> pdd;
const int inf = 0x3f3f3f3f;
const ll INF = 0x3f3f3f3f3f3f3f3f;
const int mod = 1e9 + 7;
const double eps = 1e-9;
const int N = 2e5 + 10, M = 4e5 + 10;
int n, k, q;
int a[N];
int A(int a, int b)
{
int res = 1;
for (int i = a, j = 1; j <= b; --i, ++j)
{
res *= a;
}
return res;
}
void solve()
{
cin >> n >> k >> q;
for (int i = 1; i <= n; ++i)
cin >> a[i];
// cout << n << " " << k << " " << q << endl;
int len = 0;
int ans = 0;
for (int i = 1; i <= n; ++i)
{
if (a[i] <= q)
len++;
else
{
if (len >= k)
{
int t = len;
while (t >= k)
{
ans += A(t - k + 1, 1);
t--;
}
}
len = 0;
}
}
if (len >= k)
{
int t = len;
while (t >= k)
{
ans += A(t - k + 1, 1);
t--;
}
}
cout << ans << endl;
}
signed main(void)
{
Zeoy;
int T = 1;
cin >> T;
while (T--)
{
solve();
}
return 0;
}
E. Character Blocking
题解:模拟
- 我们不妨记录初始状态下两个字符串之间有\(cnt\)个字符不相同
- 对于封锁操作以及解锁我们可以利用邻接表思想实现
- 对于交换操作,我们正常模拟,并维护\(cnt\)
- 对于检查操作,如果\(cnt=0\),那么相等,否则不相等
- 所以整个模拟过程的核心就是维护好两个字符串之间有多少个字符不相同
#include <bits/stdc++.h>
#define Zeoy std::ios::sync_with_stdio(false), std::cin.tie(0), std::cout.tie(0)
#define all(x) (x).begin(), (x).end()
#define rson id << 1 | 1
#define lson id << 1
#define int long long
#define mpk make_pair
#define endl '\n'
using namespace std;
typedef unsigned long long ULL;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<double, double> pdd;
const int inf = 0x3f3f3f3f;
const ll INF = 0x3f3f3f3f3f3f3f3f;
const int mod = 1e9 + 7;
const double eps = 1e-9;
const int N = 4e5 + 10, M = 4e5 + 10;
int t, q;
vector<int> g[N];
void solve()
{
string s1, s2;
cin >> s1 >> s2;
cin >> t >> q;
for (int i = 1; i <= q + 10; ++i)
g[i].clear();
int cnt = 0;
for (int i = 0; i < s1.size(); ++i)
if (s1[i] != s2[i])
cnt++;
s1 = " " + s1;
s2 = " " + s2;
vector<int> vis(s1.size() + 10);
// cout << cnt << endl;
for (int i = 1; i <= q; ++i)
{
int op, p, l, r, p1, p2;
cin >> op;
while (g[i].size())
{
int pos = g[i].back();
vis[pos] = 0;
if (s1[pos] != s2[pos])
cnt++;
g[i].pop_back();
}
if (op == 1)
{
cin >> p;
vis[p] = 1;
g[i + t].push_back(p);
if (s1[p] != s2[p])
cnt--;
}
else if (op == 2)
{
cin >> l >> p1 >> r >> p2;
if (l == 1 && r == 1)
{
if (s1[p1] != s2[p1] && !vis[p1])
cnt--;
if (s1[p2] != s2[p2] && !vis[p2])
cnt--;
swap(s1[p1], s1[p2]);
if (s1[p1] != s2[p1] && !vis[p1])
cnt++;
if (s1[p2] != s2[p2] && !vis[p2])
cnt++;
}
else if (l == 1 && r == 2)
{
if (s1[p1] != s2[p1] && !vis[p1])
cnt--;
if (s1[p2] != s2[p2] && !vis[p2])
cnt--;
swap(s1[p1], s2[p2]);
if (s1[p1] != s2[p1] && !vis[p1])
cnt++;
if (s1[p2] != s2[p2] && !vis[p2])
cnt++;
}
else if (l == 2 && r == 1)
{
if (s1[p1] != s2[p1] && !vis[p1])
cnt--;
if (s1[p2] != s2[p2] && !vis[p2])
cnt--;
swap(s2[p1], s1[p2]);
if (s1[p1] != s2[p1] && !vis[p1])
cnt++;
if (s1[p2] != s2[p2] && !vis[p2])
cnt++;
}
else if (l == 2 && r == 2)
{
if (s1[p1] != s2[p1] && !vis[p1])
cnt--;
if (s1[p2] != s2[p2] && !vis[p2])
cnt--;
swap(s2[p1], s2[p2]);
if (s1[p1] != s2[p1] && !vis[p1])
cnt++;
if (s1[p2] != s2[p2] && !vis[p2])
cnt++;
}
}
else
{
if (cnt == 0)
cout << "YES" << endl;
else
cout << "NO" << endl;
}
}
}
signed main(void)
{
Zeoy;
int T = 1;
cin >> T;
while (T--)
{
solve();
}
return 0;
}
Codeforces Round 878 (Div3)的更多相关文章
- 【赛时总结】◇赛时·V◇ Codeforces Round #486 Div3
◇赛时·V◇ Codeforces Round #486 Div3 又是一场历史悠久的比赛,老师拉着我回来考古了……为了不抢了后面一些同学的排名,我没有做A题 ◆ 题目&解析 [B题]Subs ...
- CodeForces Round #527 (Div3) B. Teams Forming
http://codeforces.com/contest/1092/problem/B There are nn students in a university. The number of st ...
- CodeForces Round#480 div3 第2场
这次div3比上次多一道, 也加了半小时, 说区分不出1600以上的水平.(我也不清楚). A. Remove Duplicates 题意:给你一个数组,删除这个数组中相同的元素, 并且保留右边的元素 ...
- CODEFORCES ROUND#624 DIV3
这次比赛从名字就可以看出非常水,然鹅因为第一次打codeforces不太熟悉操作只来的及做签到题(还错了一次) A,B,C都是签到题考点思维就不写了 D题 https://codeforces.ml/ ...
- A. Launch of Collider Codeforces Round #363 (Div2)
A. Launch of Collider time limit per test 2 seconds memory limit per test 256 megabytes input standa ...
- CodeForces Round #527 (Div3) D2. Great Vova Wall (Version 2)
http://codeforces.com/contest/1092/problem/D2 Vova's family is building the Great Vova Wall (named b ...
- CodeForces Round #527 (Div3) D1. Great Vova Wall (Version 1)
http://codeforces.com/contest/1092/problem/D1 Vova's family is building the Great Vova Wall (named b ...
- CodeForces Round #527 (Div3) C. Prefixes and Suffixes
http://codeforces.com/contest/1092/problem/C Ivan wants to play a game with you. He picked some stri ...
- CodeForces Round #527 (Div3) A. Uniform String
http://codeforces.com/contest/1092/problem/A You are given two integers nn and kk. Your task is to c ...
- 「暑期训练」「Brute Force」 Optimal Point on a Line (Educational Codeforces Round 16, B)
题意 You are given n points on a line with their coordinates $x_i$. Find the point x so the sum of dis ...
随机推荐
- 基于GitLab+Jenkin-CICD方案实践
前言 笔录于2022- 官网:https://about.gitlab.com/ 参考文档:https://docs.gitlab.com/ee/ci/ 清华源:清华大学开源软件镜像站 | Tsing ...
- C++: 虚函数,一些可能被忽视的细节
C++: 虚函数,一些可能被忽视的细节 引言:关于C++虚函数,对某些细节的理解不深入,可能导致我们的程序无法按预期结果运行,或是表明我们对其基本原理理解不够透彻.本文详细解答以下几个问题:实现多态, ...
- 使用 `Roslyn` 分析器和修复器 对异步方法规范化返回Async结尾
之前写过一篇使用修复器帮助添加头部注释文本的功能,今天使用Roslyn的代码修复器对异步返回方法规范化的功能 实现分析器 首先需要实现分析器,使用RegisterSyntaxNodeAction,分析 ...
- ASP.NET Core – Swagger API Versioning
前言 Versioning 会导致 Swagger 直接坏掉. 因为 1 个文档无法支持多个版本. 所以需要每一个版本做一个文档. 主要参考 Integrating ASP.NET Core Api ...
- SpringMVC —— 响应
响应页面 响应文本数据 响应json数据 响应json集合数据 注解 转换json时使用了类型转换器
- SpringMVC —— 请求参数
请求映射路径 请求方式 get请求传参 post请求传参 POST请求中文参数乱码问题 请求参数(五种类型数据参数) ...
- Nuxt Kit 中的模板处理
title: Nuxt Kit 中的模板处理 date: 2024/9/20 updated: 2024/9/20 author: cmdragon excerpt: 摘要:本文详细介绍了在Nuxt ...
- 一次基于AST的大规模代码迁移实践
作者:来自 vivo 互联网大前端团队- Wei Xing 在研发项目过程中,我们经常会遇到技术架构迭代更新的需求,通过技术的迭代更新,让项目从新的技术特性中受益,但由于很多新的技术迭代版本并不能完全 ...
- 填坑 CentOS7 使用 Python3 安装 Cython 编写扩展
前文参见 <CentOS 7 下通过 Cython 编写 python 扩展>, 用的是 Python2.7,本文用的是 Python3.6 yum install python3 pyt ...
- 五行八字在线排盘api接口免费版_json数据格式奥顺互联内部接口
「八字在线排盘」谁都想知道自己一生中的事业.财运.婚姻.功名.健康.性格.流年运程将是怎样,通过八字排盘,四柱八字排盘会有你想知道的答案.一个人出生的年月时天干地支的排列组合(即八字)就是命.不过仅凭 ...


