9.03 京东笔试
第一题
// // Created by mm on 2022/9/3 0003. #include "bits/stdc++.h" using namespace std; int solve(vector<int>&vec){ int ret; sort(vec.begin(),vec.end()); int t = vec.back(); for(int i=0;i<vec.size();i++){ if(vec[i]<t){ ret++; } else if(vec[i]==t){ continue; } } return ret; } int main(){ int n; scanf("%d\n",&n); string str; getline(cin,str); stringstream ss(str); string temp; vector<int> vec; while (getline(ss, temp, ' ')) { vec.push_back(stoi(temp)); } int ret = solve(vec); cout<<ret; return 0; }
第二题
#include "bits/stdc++.h" using namespace std; int solve(vector<int>&vec){ vector<int>dp(11,INT_MAX/2); dp[1] = 0; dp[2] = 1; for(int i=3;i<(int)dp.size();i++){ dp[i] = i-1; for(int k=1;k<i;++k){ dp[i] = min(dp[i],k+dp[i-k]); } for(int j = 2;j<=(int)sqrt(i);j++){ if(i%j==0){ dp[i] = min(dp[i],dp[i/j]+dp[j]+1); } else{ dp[i] = min(dp[i],j+dp[i-j]); } } } int ret = 0; for(int i=0;i<(int)vec.size();i++){ ret += dp[vec[i]]; } return ret; } int main(){ int n; scanf("%d\n",&n); string str; getline(cin,str); stringstream ss(str); string temp; vector<int>vec; while (getline(ss, temp, ' ')) { vec.push_back(stoll(temp)); } int ret = solve(vec); cout<<ret; return 0; }
第三题
通过率22%
#京东笔试#