[CF1083B]The Fair Nut and Strings
题目大意:在给定的长度为$n(n\leqslant5\times10^5)$的字符串$A$和字符串$B$中找到最多$k$个字符串,使得这$k$个字符串不同的前缀字符串的数量最多(只包含字符$a$和$b$)。
题解:考虑给这$k$个字符串建一个$trie$树,答案就是它所含的节点数,考虑贪心,在每一层尽可能多的分叉。注意一层最多只能有$k$个点
卡点:无
C++ Code:
#include <cstdio>
#define maxn 500010
int n, k;
long long ans;
char A[maxn], B[maxn];
int main() {
scanf("%d%d", &n, &k);
scanf("%s%s", A, B);
long long now = 1;
for (int i = 0; i < n; ++i) {
now <<= 1;
now -= (A[i] == 'b') + (B[i] == 'a');
if (now >= k) {
printf("%lld\n", ans + static_cast<long long> (n - i) * k);
return 0;
}
ans += now;
}
printf("%lld\n", ans);
return 0;
}
[CF1083B]The Fair Nut and Strings的更多相关文章
- CF 1083 B. The Fair Nut and Strings
B. The Fair Nut and Strings 题目链接 题意: 在给定的字符串a和字符串b中找到最多k个字符串,使得不同的前缀字符串的数量最多. 分析: 建出trie树,给定的两个字符串就 ...
- Codeforces Round #526 (Div. 2) E. The Fair Nut and Strings
E. The Fair Nut and Strings 题目链接:https://codeforces.com/contest/1084/problem/E 题意: 输入n,k,k代表一共有长度为n的 ...
- 【贪心/Trie】【CF1083B】 The Fair Nut and Strings
Description 有 \(k\) 个长度为 \(n\) 的只含 \(a\) 或 \(b\) 字符串,并不知道它们具体是多少,只知道它们的字典序不小于字符串 \(A\),同时不大于字符串 \(B\ ...
- Codeforces 1083B The Fair Nut and Strings
Description 给定两个由 \('a'\), \('b'\) 组成的字符串 \(a\), \(b\),以及两个整数 \(n\) 和 \(k\) \(n\) 表示字符串 \(a\),\(b\) ...
- CF1083B The Fair Nut and String
题意 给出两个长度为n的01字符串S和T. 选出k个字典序在S和T之间的长度为n的01字符串,使得尽可能多的字符串满足其是所选字符串中至少一个串的前缀. 这是一道思路比较奇怪的类似计数dp的题. 首先 ...
- CF1083E The Fair Nut and Rectangles
CF1083E The Fair Nut and Rectangles 给定 \(n\) 个平面直角坐标系中左下角为坐标原点,右上角为 \((x_i,\ y_i)\) 的互不包含的矩形,每一个矩形拥有 ...
- CF 1083 A. The Fair Nut and the Best Path
A. The Fair Nut and the Best Path https://codeforces.com/contest/1083/problem/A 题意: 在一棵树内找一条路径,使得从起点 ...
- CF1083A The Fair Nut and the Best Path
CF1083A The Fair Nut and the Best Path 先把边权搞成点权(其实也可以不用),那么就是询问树上路径的最大权值. 任意时刻权值非负的限制可以不用管,因为若走路径 \( ...
- Codeforces Round #526 (Div. 2) D. The Fair Nut and the Best Path
D. The Fair Nut and the Best Path 题目链接:https://codeforces.com/contest/1084/problem/D 题意: 给出一棵树,走不重复的 ...
随机推荐
- LeetCode: 31. Next Permutation (Medium)
1. 原题链接 https://leetcode.com/problems/next-permutation/description/ 2. 题目要求 给出一个整型数组,让我们给出下一个排序情况.注意 ...
- Python3 linux安装
./configure --prefix=/usr/local/python3 --with-ssl --enable-optimizations make && make insta ...
- CC2541工程优化等级的问题
1. 调试工程的时候发现,优化等级稍微调高一级,就容易出问题,只能用None,其他等级会出现数据丢失的现象.
- tcpdump使用
1. tcpdump选项 它的命令格式为: tcpdump [ -DenNqvX ] [ -c count ] [ -F file ] [ -i interface ] [ -r file ][ -s ...
- 聊聊WS-Federation
本文来自网易云社区 单点登录(Single Sign On),简称为 SSO,目前已经被大家所熟知.简单的说, 就是在多个应用系统中,用户只需要登录一次就可以访问所有相互信任的应用系统. 举例: 我们 ...
- 【CSV数据文件】
文件参数化设置方法
- ionic 提示框
html文件 <ion-header> <ion-navbar> <ion-title>Toast</ion-title> </ion-navba ...
- P4编程环境搭建遇到的问题与解决方法
在经历了无数的折腾之后,算是折腾,最后采用的是陈翔学长的脚本加上可爱的shell调整装好的. 链接:p4Install 也许是ubuntu18.04的问题,也有可能是我自己把这个系统折腾的有点杂乱的原 ...
- TCP系列22—重传—12、Forward Retransmit
一.概述 forward retransmit相关的内容在RFC6675中有描述,可以参考RFC6675 section 4中NextSeg ()的定义.forward retransmit中文名可以 ...
- 不同品牌交换机设置telnet方法
H3C交换机:1.设置telnet system-view super password level 3 cipher ******telnet server enable user-interfac ...