2022.11.1每日刷题打卡

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

 题意<传送门>

思路:水题很水~贪心就是\sum _{i = 1}^{n}a_{i}+b_{i} - max(b_{i})

#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;
}

 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值