CareerCup Divide n cakes to k different people
来源:互联网 发布:什么是物联网大数据 编辑:程序博客网 时间:2024/06/05 15:56
In a party there are n different-flavored cakes of volume V1, V2, V3 ... Vn each. Need to divide them into K people present in the
party such that
- Each member of party gets equal volume of cake (say V, which is the solution we are looking for)
- A given member should get a cake of single flavour only i.e. You cannot distribute parts of different flavored cakes to same
member.
- Minimum volume of cake gets wasted after distribution so that means a maximum distribution policy
-------------------------------------------------------------------------------------
Binary Search: We assume the volumes are int. If not, we should define an epi.
class Solution { public: bool isDivided(vector<int>& vi, int K, int v) { } int getVol(vector<int>& vi, int K) { int sum = 0, l = 0, r = 0, maxVol = 0, mid; sort(vi.begin(),vi.end(),greater<int>); for (int i = 0; i < vi.size(); ++i) sum += vi[i]; l = vi[0] / K; r = sum / K; while (l <= r) { mid = (l + r) / 2; if (isDivided(vi, K, mid)) { if (mid > maxVol) { maxVol = mid; l = mid + 1; } else r = mid - 1; } else r = mid - 1; } return maxVol; }}
0 0
- CareerCup Divide n cakes to k different people
- [Divide and Conquer]241. Different Ways to Add Parentheses
- Leetcode divide & conquer || Different Ways to Add Parentheses
- 【算法】【Divide and conquer】Different Ways to Add Parentheses
- 241. Different Ways to Add Parentheses(divide and conquer)
- Divide and Conquer -- Leetcode problem241:Different Ways to Add Parentheses
- Divide and Conquer:241. Different Ways to Add Parentheses
- cakes
- leetcode_c++:Divide and Conquer:Different Ways to Add Parentheses(241)
- Divide and Conquer (1) -- Kth Largest Element in an Array,Different Ways to Add Parentheses
- leetCode刷题归纳-Divide and Conquer(241. Different Ways to Add Parentheses)
- CareerCup Maximum of all subarrays of size k (Added a O(n) method)
- CareerCup Number of ways to take n identical objects out of a bucket
- CareerCup How to find medium of 1 billion numbers across N distributed machines efficiently?
- 【ZOJ3916 2016年浙大2月月赛B】【贪心 STL-SET】Buy Cakes n蛋糕k张折扣券蛋糕双价最多能买蛋糕数
- CareerCup Given a binary matrix of N X N of integers , you need to return only unique rows of binary
- CareerCup Facebook Judge Whether a K-palindrome
- Use Power to Help people
- H264--3 NAL
- 每天读一遍,不久你就会变
- 【插入排序】希尔排序--Java
- H264--4 encode
- 内存检测工具-kmemcheck kmemleak
- CareerCup Divide n cakes to k different people
- H264---5 decode
- cocos2dx lua文件的加载问题
- [0day安全-学习总结]第三章开发shellcode的艺术之shellocde编码解码原理
- 充分利用HTML来让技术文章更加易读——初步探索
- “核心员工”与“人才备份”
- 1000. 用指针方法处理数的排序
- LeetCode---Maximum Subarray
- GSM MAP Forward SMS Signaling Introduction