#滴滴23秋招笔试有点儿难啊# #滴滴笔试#
大佬帮我看看第一题这个代码为啥错了
int recursion(vector& nums, int left, int right, double sum, double tt, int k)
{
if (tt * k > nums[right])
{
return right - left + 1;
}
int l = recursion(nums, left + 1, right, sum - nums[left], (double)(sum - nums[left]) / (double)(right - left), k);
int r = recursion(nums, left, right - 1, sum - nums[right], (double)(sum - nums[right]) / (double)(right - left), k);
return max(l, r);
}
int main()
{
int n, k;
cin >> n >> k;
vector nums;
double sum = 0.0;
for (int i = 0; i < n; ++i)
{
int temp;
cin >> temp;
sum += temp;
nums.push_back(temp);
}
sort(nums.begin(), nums.end());
double tt = (double)sum / (double)n;
int left = 0, right = n - 1;
cout << recursion(nums, left, right, sum, tt, k) << endl;
return 0;
}
大佬帮我看看第一题这个代码为啥错了
int recursion(vector
{
if (tt * k > nums[right])
{
return right - left + 1;
}
int l = recursion(nums, left + 1, right, sum - nums[left], (double)(sum - nums[left]) / (double)(right - left), k);
int r = recursion(nums, left, right - 1, sum - nums[right], (double)(sum - nums[right]) / (double)(right - left), k);
return max(l, r);
}
int main()
{
int n, k;
cin >> n >> k;
vector
double sum = 0.0;
for (int i = 0; i < n; ++i)
{
int temp;
cin >> temp;
sum += temp;
nums.push_back(temp);
}
sort(nums.begin(), nums.end());
double tt = (double)sum / (double)n;
int left = 0, right = n - 1;
cout << recursion(nums, left, right, sum, tt, k) << endl;
return 0;
}
全部评论
过了81 出错了
相关推荐
点赞 评论 收藏
分享