Digital Logarithm
题意 传送门
思路:既然是要排序后最小操作数,那么我们选择优先队列去存储,这样队列是默认排序的所以只需要按题意操作就可以了
AC代码:
#include <bits/stdc++.h>
int f(int x){
int ans = 0;
while(x) x /= 10, ans++;
return ans;
}
int main() {
std::ios::sync_with_stdio(false);
std::cin.tie(nullptr);
int t;
std::cin >> t;
while (t--) {
int n, x;
std::cin >> n;
std::priority_queue<int> a, b;
for (int i = 0; i < n; i++) {
std::cin >> x;
a.push(x);
}
for (int i = 0; i < n; i++) {
std::cin >> x;
b.push(x);
}
int ans = 0;
while(!a.empty()) {
int x = a.top();
int y = b.top();
if(x == y) a.pop(), b.pop();
else if(x < y) b.push(f(y)), b.pop(), ans++;
else a.push(f(x)), a.pop(), ans++;
}
std::cout << ans << "\n";
}
return 0;
}
Death's Blessing
题意<传送门>
思路:水题很水~贪心就是
#include <bits/stdc++.h>
#define x first
#define y second
#define int long long
typedef std::pair<int, int> PII;
signed main() {
std::ios::sync_with_stdio(false);
std::cin.tie(nullptr);
int t;
std::cin >> t;
while (t--) {
int n;
std::cin >> n;
std::vector<PII> a(n);
int ans = 0;
for(int i = 0; i < n; i++){
std::cin >> a[i].x;
ans += a[i].x;
}
int max = 0;
for(int i = 0; i < n; i ++){
std::cin >> a[i].y;
max = std::max(a[i].y, max);
ans += a[i].y;
}
std::cout << ans - max << "\n";
}
return 0;
}