求网站2021给个网址,网站简单代码,佛山网站建设运营,wordpress comment_form();A. Is It a Cat?定义满足条件的字符串为#xff1a;其中仅可能含有meow四种字母的大小写#xff0c;而且相同种类的字母必须挨在一起#xff0c;四种字母的顺序必须按照meow排列。给出一个字母串#xff0c;求是否满足条件。思路#xff1a;感觉是个很麻烦的模拟。首先把…A. Is It a Cat?定义满足条件的字符串为其中仅可能含有meow四种字母的大小写而且相同种类的字母必须挨在一起四种字母的顺序必须按照meow排列。给出一个字母串求是否满足条件。思路感觉是个很麻烦的模拟。首先把大小写全都转为小写字母再把相同的字母合并最后判断一下字母的种类和顺序。AC Code#include bits/stdc.htypedef long long ll;
const int N 1e6 5;
int t, n;
std::string s;int main() {std::ios::sync_with_stdio(false);std::cin.tie(0);std::cout.tie(0);std::cin t;while(t --) {std::cin n s;std::vectorchar vec;char c;if(s[0] A s[0] Z)vec.push_back((char)(s[0] - A a)), c (char)(s[0] - A a);elsevec.push_back(s[0]), c s[0];for(int i 1; i n; i ) {if(s[i] A s[i] Z)s[i] (char)(s[i] - A a);if(s[i] ! c)vec.push_back(s[i]), c s[i];}if(vec.size() 4 vec[0] m vec[1] e vec[2] o vec[3] w)std::cout YES \n;elsestd::cout NO \n;}return 0;
}B. Count the Number of Pairs给出一个字符串对于同一种字母一个大写一个小写可以凑成一对给出k次操作可以将任意一个字母大小写翻转问给出的字符串中最多可以有多少对字母。思路统计字符串中大小写字母的个数先统计不经过修改可以得到多少串然后拥挤通过修改可以最多得到多少对即可。AC Code#include bits/stdc.htypedef long long ll;
const int N 1e6 5;
int t, n, k;
std::string s;int main() {std::ios::sync_with_stdio(false);std::cin.tie(0);std::cout.tie(0);std::cin t;while(t --) {std::cin n k s;int ans 0;std::unordered_mapchar, int mpl, mpu;for(int i 0; i n; i ) {if(s[i] a s[i] z)mpl[s[i]] ;elsempu[s[i]] ;}for(auto [x, y] : mpl) {if(y mpu[x - a A]) {ans std::min(y, mpu[x - a A]);mpl[x] - std::min(y, mpu[x - a A]);mpu[x - a A] - y, mpu[x - a A];}}for(auto [x, y] : mpl) {if(y 2) {int res std::min(k, y / 2);ans res, k - res, y - res * 2;}}for(auto [x, y] : mpu) {if(y 2) {int res std::min(k, y / 2);y - res * 2, ans res, k - res;}}std::cout ans \n;}return 0;
}C. Powering the Hero给出一个数组其中非0的数字可以被存下来放在一堆中为0的数可以加上现有的非0数中的一个数。求所有的为0的值通过修改得到的和最大是多少。思路优先队列即可每次遇到一个非0的数就将其放进队列中遇到为0的数就取出队列中最大的数加入答案并pop出队列easy版本做法与hard版本相同时间复杂度O(nlogn)能过。AC Code#include bits/stdc.htypedef long long ll;
const int N 1e6 5;
int t, n;
ll a[N];int main() {std::ios::sync_with_stdio(false);std::cin.tie(0);std::cout.tie(0);std::cin t;while(t --) {std::cin n;std::priority_queuell pq;ll ans 0;for(int i 1; i n; i ) {std::cin a[i];if(a[i])pq.push(a[i]);if(!a[i] !pq.empty()) {ans pq.top();pq.pop();}}std::cout ans \n;}return 0;
}D. Remove Two Letters在字符串中去掉任意两个相连的字母剩下的串相连求可以得到多少种不同的字符串。思路一开始想hash但是又不太会hash又感觉hash很容易被卡。可以这样考虑从头开始每次向后转移去掉的两个字母就是加上上一对字母的前一个去掉后一对字母的后一个那直接比较这两个字母即可只要不同就对答案有贡献。AC Code#include bits/stdc.htypedef long long ll;
const int N 1e6 5;
int t, n;
std::string s;int main() {std::ios::sync_with_stdio(false);std::cin.tie(0);std::cout.tie(0);std::cin t;while(t --) {std::cin n s;int ans 0;for(int i 1; i n - 1; i ) {if(s[i - 1] ! s[i 1]) {ans ;}}std::cout ans 1 \n;}return 0;
}E. Unforgivable Curse给出两个字符串s和t目标是把s修改为t每次修改可以交换相距k或k1位置的字母问是否能修改成功。思路很显然如果某个字符需要修改但是它距离左右边界的距离都小于k那必然没法修改。对于其他的位置我们一定可以找到两个位置互换的方法即可以通过中间字符修改而顺着修改的顺序逆着回去可以复原原来在正确位置的字母。easy版本与hard版本相同。AC Code#include bits/stdc.htypedef long long ll;
const int N 1e6 5;
int T, n, k;
std::string s, t;int main() {std::ios::sync_with_stdio(false);std::cin.tie(0);std::cout.tie(0);std::cin T;while(T --) {std::cin n k;std::cin s t;std::mapchar, int mp, mpp;for(int i 0; i n; i ) {mp[s[i]] ;mpp[t[i]] ;}bool flag true;for(auto [x, y] : mp) {if(y ! mpp[x]) {flag false;break;}}if(!flag) {std::cout NO \n;continue;}for(int i 0; i n; i ) {if(s[i] ! t[i] std::max(i, n - i - 1) k) {flag false;break;}}std::cout (flag ? YES : NO) \n;}return 0;
}F. Dasha and Nightmares给出n个字符串问有多少对不同的字符串使得两个字符串连接起来满足以下条件字符串中包含25个不同的字母每个字母的个数为奇数个字符串长度为奇数。思路思路来自cup_cpp佬。考虑哈希。但是显然STL自带的哈希表很容易会被卡掉就需要一些高端方法自定义哈希表因为是奇数所以可以采用位运算实现代码。用二进制下的26位数字存所有的目标字符串开26个哈希表存对于每个字母不存在时满足条件的方案数。AC Code#include bits/stdc.htypedef long long ll;
#define int long long
const int N 2e5 5;
int n;
int num[30], cnt[30];
std::string s;struct custom_hash {static uint64_t splitmix64(uint64_t x) {x 0x9e3779b97f4a7c15;x (x ^ (x 30)) * 0xbf58476d1ce4e5b9;x (x ^ (x 27)) * 0x94d049bb133111eb;return x ^ (x 31);}size_t operator()(uint64_t x) const {static const uint64_t FIXED_RANDOM std::chrono::steady_clock::now().time_since_epoch().count();return splitmix64(x FIXED_RANDOM);}
};signed main() {std::ios::sync_with_stdio(false);std::cin.tie(0);std::cout.tie(0);std::cin n;for(int i 0; i 26; i ) {num[i] ((1 26) - 1) ^ (1 i);}std::unordered_mapint, int, custom_hash mp[26];for(int i 0; i 26; i )mp[i].reserve(n);int ans 0;for(int i 0; i n; i ) {std::cin s;int mask 0;memset(cnt, 0, sizeof(cnt));for(auto u : s)cnt[u - a] ;for(int i 0; i 26; i ) {if(cnt[i] 1)mask ^ (1 i);}for(int i 0; i 26; i ) {if(!cnt[i] mp[i].count(mask ^ num[i]))ans mp[i][mask ^ num[i]];}for(int i 0; i 26; i ) {if(!cnt[i])mp[i][mask] ;}}std::cout ans \n;return 0;
}