小红的奇偶抽取
#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;
}
小红装电脑
#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;
}