蚂蚁集团23年秋招开发岗1卷

小红的奇偶抽取

#include <iostream>
#include <stack>
using namespace std;

int main() {
    stack<long long>ji,ou;
    long long n;
    cin>>n;
    while(n!=0){
        if(n%2==0){
            ou.push(n%10);
        }else{
            ji.push(n%10);
        }
        n/=10;

    }
    long long left=0,right=0;
    while(!ji.empty()){
        left=left*10+ji.top();
        ji.pop();
    }
    while (!ou.empty()) {
        right=right*10+ou.top();
        ou.pop();
    }
    cout<<abs(left-right);
    return 0;
}
// 64 位输出请用 printf("%lld")

小红装电脑

#include <iostream>
#include <algorithm>
#include <map>
using namespace std;
int main(){
    int n, x;
    cin >> n >> x;
    int **cost = new int*[n];
    int **perf = new int*[n];
    int *comp_nums = new int[n];
    for (int t = 0; t < n; t++){
        cin >> comp_nums[t];
        cost[t] = new int[comp_nums[t]];
        perf[t] = new int[comp_nums[t]];
        for (int i = 0; i < comp_nums[t]; i++){
            cin >> cost[t][i];
        }
        for (int i = 0; i < comp_nums[t]; i++){
            cin >> perf[t][i];
        }
    }
    map<long long, long long> dp[45];
    dp[0][0] = 0;
    long long max_perf = -1;
    for (long long t = 0; t < n; t++){
        for (auto iter = dp[t].begin(); iter != dp[t].end(); iter++){
            long long dp_cost = iter->first;
            long long dp_perf = iter->second;
            for (long long i = 0; i < comp_nums[t]; i++){
                if (dp_cost+cost[t][i] <= x){
                    dp[t+1][dp_cost+cost[t][i]] = max(dp[t+1][dp_cost+cost[t][i]], dp_perf+perf[t][i]);
                    if ((t+1 == n) && (dp[t+1][dp_cost+cost[t][i]] > max_perf)){
                        max_perf = dp[t+1][dp_cost+cost[t][i]];
                    }
                }
            }
        }
    }
    cout << max_perf;
    return 0;
}

  • 3
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值