9.19迅雷笔试
1、能达到target的最小操作数量,递归,target奇数减一偶数除以二 100%
2、分割三个红包池,暴力解决 100%
#include <bits/stdc++.h> using namespace std; vector<int> nums; vector<int> pre; vector<int> path; int ret = 0; void callback(int idx){ if(path.size() == 2){ int sum1 = pre[path[0]], sum2 = (pre[path[1]] - pre[path[0]]), sum3 = pre[pre.size()-1] - pre[path[1]]; if(sum1<= sum2 && sum2<= sum3){ ret += 1; } return; } if(idx == nums.size()){ return; } for(int i=idx; i< nums.size(); i++){ path.push_back(i); callback(i+1); path.pop_back(); } } int main(){ string nums_str; getline(cin, nums_str); stringstream in(nums_str); string num; while(getline(in, num, ' ')){ nums.push_back(stoi(num)); } pre.resize(nums.size()); for(int i=0; i< nums.size(); i++){ pre[i] = nums[i]; if(i> 0){ pre[i] += pre[i-1]; } } callback(0); cout << ret; return 0; }3、正确的号码列表 80% 不知为何
#include <bits/stdc++.h> using namespace std; int main(){ int t; cin >> t; while(t--> 0){ int num; cin >> num; vector<string> nums(num); for(int i=0; i< num; i++){ cin >> nums[i]; } sort(nums.begin(), nums.end()); int i=1; for(; i< nums.size(); i++){ if(nums[i].find(nums[i-1]) == 0){ cout << "NO" << endl; break; } } if(i == nums.size()){ cout << "YES" << endl; } } return 0; }