总结
虽然这次周赛有2题hard,但其实都比较简单。第一题特判每一条即可,第二题就是一道简单的二分。第三题的话,通过哈希映射存储转换关系后暴力,第四题就是一道普通的双指针算法。总体来看难度不大。因为昨天刚考完六级和朋友吃饭去了,所以没有参加hh
6095. 强密码检验器 II
// shiran
#include <bits/stdc++.h>
using namespace std;
#define rep(i, a, n) for (int i = a; i < n; i++)
#define per(i, n, a) for (int i = n - 1; i >= a; i--)
#define sz(x) (int)size(x)
#define fi first
#define se second
#define all(x) x.begin(), x.end()
#define pb push_back
#define mk make_mair
typedef long long ll;
typedef pair<int, int> PII;
const int mod = 1e9+7;
const int N = 200010, M = 300010;
int dx[4] = {-1, 0, 1, 0}, dy[4] = {0, 1, 0, -1};
string str = "!@#$%^&*()-+";
class Solution {
public:
bool strongPasswordCheckerII(string s) {
if (sz(s) < 8) return false;
bool a = false, b = false, c = false, d = false;
for (int i = 0; i < sz(s); i ++ )
{
if (s[i] >= 'a' && s[i] <= 'z') a = true;
if (s[i] >= 'A' && s[i] <= 'Z') b = true;
if (s[i] >= '0' && s[i] <= '9') c = true;
for (int j = 0; j < sz(str); j ++ )
if (s[i] == str[j])
d = true;
if (i && s[i] == s[i - 1])
return false;
}
return a && b && c && d;
}
};
6096. 咒语和药水的成功对数
// shiran
#include <bits/stdc++.h>
using namespace std;
#define rep(i, a, n) for (int i = a; i < n; i++)
#define per(i, n, a) for (int i = n - 1; i >= a; i--)
#define sz(x) (int)size(x)
#define fi first
#define se second
#define all(x) x.begin(), x.end()
#define pb push_back
#define mk make_mair
typedef long long ll;
typedef pair<int, int> PII;
const int mod = 1e9+7;
const int N = 200010, M = 300010;
int dx[4] = {-1, 0, 1, 0}, dy[4] = {0, 1, 0, -1};
class Solution {
public:
vector<int> successfulPairs(vector<int>& v, vector<int>& p, long long s) {
sort(all(p));
vector<int> ans;
for (auto& t : v)
{
int l = 0, r = sz(p);
while (l < r)
{
int mid = l + r >> 1;
if (1ll * t * p[mid] >= s) r = mid;
else l = mid + 1;
}
ans.pb(sz(p) - r);
}
return ans;
}
};
6097. 替换字符后匹配
class Solution {
public:
bool matchReplacement(string s, string sub, vector<vector<char>>& mappings) {
set<int> mp;
for (auto& t : mappings)
mp.insert(t[0] * 256 + t[1]);
for (int i = 0; i + sub.size() - 1 < s.size(); i ++ )
{
bool flag = true;
for (int j = 0; j < sub.size(); j ++ )
{
if (s[i + j] != sub[j] && !mp.count(sub[j] * 256 + s[i + j]))
{
flag = false;
break;
}
}
if (flag) return true;
}
return false;
}
};
6098. 统计得分小于 K 的子数组数目
class Solution {
public:
long long countSubarrays(vector<int>& nums, long long k) {
long long ans = 0, sum = 0;
for (int i = 0, j = 0; i < nums.size(); i ++ ) {
sum += nums[i];
while(sum * (i - j + 1) >= k) sum -= nums[j ++ ];
if (j > i) continue;
printf("%d %d\n", i, j);
ans += i - j + 1;
}
return ans;
}
};