A.Cipher Shifer
题意:(看了老半天)就是给定一个字符串 s s s,要求对其进行解密,加密步骤如下:
- 每一个字符 s [ i ] s[i] s[i]后都加上若干不同于 s [ i ] s[i] s[i]的字符,将此若干字符记作 s u b sub sub
- 完成第一个步骤后,在 s u b sub sub后面继续加一个 s [ i ] s[i] s[i]
- 继续加密 s [ i + 1 ] s[i + 1] s[i+1]直到最后一个字符
给出加密后的字符串,要求输出原来的字符串
思路:以相同字母划分,还原出加密前的字符串
signed main()
{
IO;
int t;cin >> t;
while(t -- ){
int n;cin >> n;
string s;cin >> s;
for(int i = 0;i < n;){
int j = i + 1;
while(j < n && s[j] != s[i]) j ++;
cout << s[i];
i = j + 1;
}
cout << endl;
}
return 0;
}
B.Binary Cafe
题意:给定 n n n个物品,下标从为 [ 0 , n − 1 ] [0, n - 1] [0,n−1], 其中第 i i i 个物品的价格为 2 i 2^i 2i, 现在你有 m m m 块钱,每个物品仅能购买一次或不购买,问一共有多少种购买方式,即有多少种不同的购买物品的方案
思路:要么 m + 1 m + 1 m+1 要么 2 n 2^n 2n
signed main()
{
IO;
int t;cin >> t;
while(t -- ){
int n, k;cin >> n >> k;
int nn = n;
string s;
while(n)
{
int d = n % 2;
n /= 2;
s += char('0' + d);
}
reverse(all(s));
// cout << s << endl;
int len = s.size();
if(len <= k)
{
cout << nn + 1 << endl;
}
else if(k < len)
{
cout << (int)pow(2, k) << endl;
}
}
return 0;
}
C.Ski Resort
题意:有一段数组 a a a 长度为 n n n ,下标为 [ 1 , n ] [1, n] [1,n], a [ i ] a[i] a[i] 表示第 i i i 天的温度,你仅可以在温度不大于 q q q 的日子出门,现在你想连续玩 k k k 天,有多少种方案
思路:双指针
signed main()
{
IO;
int t;cin >> t;
while(t -- ){
int n, k, q;cin >> n >> k >> q;
vector<int> a(n);
for(int i = 0;i < n;i ++) cin >> a[i], a[i] = (a[i] <= q);
int ans = 0;
for(int i = 0;i < n;)
{
int j = i;
while(j < n && a[j]) j ++;
int cnt = j - i;
i = j + 1;
if(cnt < k)
continue;
else
ans += (cnt - k + 2) * (cnt - k + 1) / 2;
}
cout << ans << endl;
}
return 0;
}
D.Wooden Toy Festival
题意:有一组数组 a a a 长度为 n n n,下标为 [ 1 , n ] [1, n] [1,n], 可以任意选定 3 3 3 个数 x , y , z x,y,z x,y,z,现在对于任意 a [ i ] a[i] a[i] 计算出 b [ i ] = m i n ( ∣ a [ i ] − x ∣ , ∣ a [ i ] − y ∣ , ∣ a [ i ] − z ∣ ) b[i] = min({|a[i] - x|, |a[i] - y|,|a[i] - z|}) b[i]=min(∣a[i]−x∣,∣a[i]−y∣,∣a[i]−z∣),求出 m a x 1 n b [ i ] max_1^nb[i] max1nb[i]最小值
思路:二分 m a x 1 n b [ i ] max_1^nb[i] max1nb[i]
signed main()
{
IO;
int t;cin >> t;
while(t -- ){
int n;cin >> n;
vector<int> a(n);
for(int i = 0;i < n;i ++)
cin >> a[i];
sort(all(a));
int l = 0, r = 2e8;
while(l < r)
{
int mid = l + r >> 1;
bool ok = false;
int p = 0;
for(int j = 0;j < 3;j ++)
{
p = upper_bound(all(a), a[p] + mid * 2) - a.begin();
if(p == n)
{
ok = true;
break;
}
}
if(ok) r = mid;
else l = mid + 1;
}
cout << r << endl;
}
return 0;
}
E.Character Blocking
题意:给你两个长度相同的字符串 s 1 s1 s1 和 s 2 s2 s2 由小写拉丁字母组成,以及一个整数 t t t
现在有 q q q 个询问,每个询问一秒钟,从第一个询问开始计数,第一个询问为第一秒
- 询问 1 1 1:锁住 s 1 s1 s1 和 s 2 s2 s2 中第 x x x 个字符 t t t 秒
- 询问 2 2 2:交换某两个给定下标的字符串的某两个字符,形如 1223 1 2 2 3 1223表示交换 s 1 [ 2 ] s1[2] s1[2]和 s 2 [ 3 ] s2[3] s2[3]
- 询问 3 3 3:查询当前 s 1 s1 s1 和 s 2 s2 s2 是否一致,不计被锁住的字符
思路:用优先队列维护被锁住的字符,哈希字符串判别字符是否一致
signed main()
{
IO;
vector<int> p(N);
p[0] = 1;
for (int i = 1; i <= 2e5; i++)
p[i] = p[i - 1] * b;
int t; cin >> t;
while (t--) {
string s[3];
cin >> s[1] >> s[2];
int sz = s[1].size();
int hash[3];
hash[1] = Hash(s[1]), hash[2] = Hash(s[2]);
int t, n; cin >> t >> n;
priority_queue<pii, vector<pii>, greater<pii>> se;
for (int i = 1; i <= n; i++) {
while (se.size())
{
bool f = true;
auto top = se.top();
if (top.first + t <= i)
{
int x = top.second;
hash[1] = hash[1] + p[sz - x] * (s[1][x - 1] - 'a');
hash[2] = hash[2] + p[sz - x] * (s[2][x - 1] - 'a');
se.pop();
f = false;
}
if (f) break;
}
int op; cin >> op;
if (op == 1) {
int x; cin >> x;
se.push({ i, x });
hash[1] = hash[1] - p[sz - x] * (s[1][x - 1] - 'a');
hash[2] = hash[2] - p[sz - x] * (s[2][x - 1] - 'a');
}
else if (op == 2)
{
int id1, id2, index1, index2;
cin >> id1 >> index1 >> id2 >> index2;
char c1 = s[id1][index1 - 1], c2 = s[id2][index2 - 1];
swap(s[id1][index1 - 1], s[id2][index2 - 1]);
hash[id1] = hash[id1] - p[sz - index1] * (c1 - 'a');
hash[id1] = hash[id1] + p[sz - index1] * (c2 - 'a');
hash[id2] = hash[id2] - p[sz - index2] * (c2 - 'a');
hash[id2] = hash[id2] + p[sz - index2] * (c1 - 'a');
}
else
{
bool ok = (hash[1] == hash[2]);
cout << (ok ? "YES\n" : "NO\n");
}
}
}
return 0;
}