A.Phone Desktop (枚举)
题意:
小 A A A的手机有一个桌面(或称启动器)。桌面可以由多个屏幕组成。每个屏幕表示为大小为 5 × 3 5 \times 3 5×3 的网格,即五行三列。
有 x x x 个应用程序的图标大小为 1 × 1 1 \times 1 1×1 个单元格;这样的图标只占屏幕的一个单元格。还有 y y y 个应用程序的图标大小为 2 × 2 2 \times 2 2×2 个单元。;这样的图标在屏幕上占据了 4 4 4 个单元格的个方格。每个屏幕的每个单元格最多只能有一个图标。
小 A A A希望在最少的屏幕上放置应用程序图标。请帮她找出所需的最少屏幕数。
分析:
我们直接枚举需要放几个屏幕,再判断是否合法即可。
代码:
#include <bits/stdc++.h>
using namespace std;
typedef long long LL;
int main() {
int t;
cin >> t;
while (t--) {
LL x, y;
cin >> x >> y;
for (int i = 0; i <= 200; i++) {
if (i * 2LL < y)
continue;
LL ans = 7LL * i + (2LL * i - y) * 4LL;
if (ans >= x) {
cout << i << endl;
break;
}
}
}
return 0;
}
B.Symmetric Encoding (模拟)
题意:
给出一个由小写字母组成的字符串 s s s 。使用以下算法对这个字符串进行编码:
- 首先,构建一个新的辅助字符串 r r r ,该字符串由字符串 s s s 中所有不同的字母组成,按字母顺序书写;
- 然后进行如下编码:将字符串 s s s 中的每个字符替换为字符串 r r r 中的对称字符(字符串 r r r 中的第一个字符将被最后一个字符替换,第二个字符将被从头开始的第二个字符替换,以此类推)。
例如, s s s = c o d e f o r c e s codeforces codeforces字符串的编码过程如下:
- 字符串 r r r 得到 c d e f o r s cdefors cdefors;
- 第一个字符 s 1 s_1 s1 = c c c 被替换为 s s s;
- 第二个字符 s 2 s_2 s2 = o o o 被替换为 e e e;
- 第三个字符 s 3 s_3 s3 = d d d 被替换为 r r r;
- …
- 最后一个字符 s 10 s_{10} s10 = s s s 被替换为 c c c。
因此,对字符串 s s s = c o d e f o r c e s codeforces codeforces 进行编码的结果是字符串 s e r o f e d s o c serofedsoc serofedsoc。
编写一个程序来执行解码,即从编码结果中还原出原始字符串 s s s 。
分析:
我们首先对字符串去重,再用 m a p map map存储映射关系,按照题意模拟即可。
代码:
#include <bits/stdc++.h>
using namespace std;
int main() {
int T;
cin >> T;
while (T--) {
int n;
cin >> n;
string a;
cin >> a;
map<char, int> mp;
vector<char> tmp;
for (auto t: a) {
if (!mp[t]) {
mp[t] = 1, tmp.push_back(t);
}
}
sort(tmp.begin(), tmp.end());
for (int i = 0; i < tmp.size(); i++) mp[tmp[i]] = i;
for (auto &t: a) cout << tmp[tmp.size() - mp[t] - 1];
cout << endl;
}
return 0;
}
C. Beautiful Triple Pairs (数学)
题意:
给出由 n n n个整数组成的数组 a a a。每个 j j j ( 1 ≤ j ≤ n − 2 1 \le j \le n - 2 1≤j≤n−2 ) 都有一个由 [ a j , a j + 1 , a j + 2 ] [a_j, a_{j + 1}, a_{j + 2}] [aj,aj+1

最低0.47元/天 解锁文章

644

被折叠的 条评论
为什么被折叠?



