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)的更多相关文章

  1. 【赛时总结】◇赛时·V◇ Codeforces Round #486 Div3

    ◇赛时·V◇ Codeforces Round #486 Div3 又是一场历史悠久的比赛,老师拉着我回来考古了……为了不抢了后面一些同学的排名,我没有做A题 ◆ 题目&解析 [B题]Subs ...

  2. 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 ...

  3. CodeForces Round#480 div3 第2场

    这次div3比上次多一道, 也加了半小时, 说区分不出1600以上的水平.(我也不清楚). A. Remove Duplicates 题意:给你一个数组,删除这个数组中相同的元素, 并且保留右边的元素 ...

  4. CODEFORCES ROUND#624 DIV3

    这次比赛从名字就可以看出非常水,然鹅因为第一次打codeforces不太熟悉操作只来的及做签到题(还错了一次) A,B,C都是签到题考点思维就不写了 D题 https://codeforces.ml/ ...

  5. 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 ...

  6. 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 ...

  7. 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 ...

  8. 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 ...

  9. 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 ...

  10. 「暑期训练」「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 ...

随机推荐

  1. C++ vector 访问元素用 at 和 [] 有什么区别?

    C++ vector 访问元素用 at and [] 有什么区别? 前言: 最近同事开发过程遇到了一个奇怪的coredump问题,崩溃位置和提交改动没有任何关系,看了几小时后来才发现原来是vector ...

  2. SoftCLT: 时间序列的软对比学习《Soft Contrastive Learning for Time Series》(时间序列、时序分类任务、软对比学习、实例上软赋值距离差异、数据空间非嵌入空间度量相似性)

    2024年6月25日,10:11,好几天没看论文了,一直在摸鱼写代码(虽然也没学会多少),今天看一篇师兄推荐的. 论文:Soft Contrastive Learning for Time Serie ...

  3. GRLSTM: 基于图的残差LSTM轨迹相似性计算《GRLSTM: Trajectory Similarity Computation with Graph-Based Residual LSTM》(轨迹路网融合、知识图谱嵌入、图神经网络、残差网络、点融合图、多头图注意力网络GAT、残差LSTM、点感知损失函数(图的点损失函数、轨迹的点损失函数))

    2023年10月18日,14:14. 来不及了,这一篇还是看的翻译. 论文:GRLSTM: Trajectory Similarity Computation with Graph-Based Res ...

  4. RSA 对称加密,对称解密----公钥私钥加密解密过程

    RSA 对称加密,对称解密----公钥私钥加密解密过程(Java) 公司说不能传铭文密码,所以只能加密,再解密:麻烦事,其实这在需求文档没有,开发时间点也没有,浪费了了一上午的时间,还占用了公司给的开 ...

  5. BOOT跳转APP,STM32F4正常,但是GD32F4起不来的问题

    问题描述:  stm32F4可以正常从BOOT跳转执行APP,到了GD32F4,卡死在APP程序的这里.  临时解决办法: APP程序内 把这两句代码都屏蔽掉就好了. 相关资料搜索: 最佳解决方案: ...

  6. 我是如何开发一款支持IDEA、PyCharm、Android Sutdio 等JB全家桶的摸鱼插件的

    公众号「古时的风筝」,专注于后端技术,尤其是 Java 及周边生态. 个人博客:www.moonkite.cn 大家好,我是风筝 前些天做了一款支持 Jetbrains 大部分 IDE 的摸鱼插件- ...

  7. 【赵渝强老师】在MongoDB中使用游标

    一.什么是游标? 游标(Cursor)是处理数据的一种方法,为了查看或者处理结果集中的数据,游标提供了在结果集中一次一行或者多行前进或向后浏览数据的能力. 游标实际上是一种能从包括多条数据记录的结果集 ...

  8. UEFI原理与编程(二)

    系统表 对UEFI应用程序和驱动程序开发人员来讲,系统表是最重要的数据结构之一,它是用户空间通往内核空间的通道.有了它,UEFI应用程序和驱动才可以访问UEFI内核.硬件资源和I/O设备. 1 在应用 ...

  9. 可视化U-Net编码器每层的输出(在已经训练好的模型下展示,并不是初始训练阶段展示)

    想看一下对于一个训练好的模型,其每一层编码阶段的可视化输出是什么样子的.我以3Dircabd肝脏血管分割为例,训练好了一个U-Net模型.然后使用该模型在推理阶段使用,并可视化了每一层编码器. 分割结 ...

  10. kotlin协程——>异步流

    异步流 挂起函数可以异步的返回单个值,但是该如何异步返回多个计算好的值呢?这正是 Kotlin 流(Flow)的 ⽤武之地. 表示多个值 在 Kotlin 中可以使⽤集合来表⽰多个值.⽐如说,我们可以 ...