- 博客(10)
- 收藏
- 关注
原创 2022.3.4-leetcode-2104(未完成)
题目:代码:#define max(a, b) (a) > (b) ? (a) : (b)#define min(a, b) (a) > (b) ? (b) : (a)long long subArrayRanges(int* nums, int numsSize){ long long temp = 0; for(int i = 0; i < numsSize; i++){ int min = INT_MAX, max = INT_MI
2022-03-04 12:22:51
208
原创 2022.2.11-leetcode-1833(贪心)
题目:代码:int cmp(const void *a, const void *b){ return *(int*)a - *(int*)b;}int maxIceCream(int* costs, int costsSize, int coins){ qsort(costs, costsSize, sizeof(int), cmp); int count = 0; for(int i = 0; i < costsSize; i++){
2022-02-11 22:11:18
454
原创 2022.2.11-leetcode-LCS 02(贪心)
题目;代码://降序int cmp21(const void *a, const void *b){ return *(int*)b - *(int*)a;}int halfQuestions(int* questions, int questionsSize){ int queAnsNum = questionsSize / 2; int list[1001] = {0};//打表 for(int i = 0; i < questionsSize
2022-02-11 21:07:57
110
原创 2022.2.10-leetcode-1710(贪心)
题目:代码:int cmp(const void *a, const void *b){ return *(*(int**)b + 1) - *(*(int**)a + 1);}int maximumUnits(int** boxTypes, int boxTypesSize, int* boxTypesColSize, int truckSize){ qsort(boxTypes, boxTypesSize, sizeof(boxTypes[0]), cmp); in
2022-02-10 17:57:19
189
原创 2022.2.10-leetcode-1402(贪心)
题目:代码:int cmp(const void *a, const void *b){ return *(int*)a - *(int*)b;}int maxSatisfaction(int* satisfaction, int satisfactionSize){//升序排序 qsort(satisfaction, satisfactionSize, 4, cmp); int satisfactionSizeLog = satisfactionSize; .
2022-02-10 16:31:16
499
原创 2022.2.9-leetcode-1561(贪心)
题目:代码:int cmp(const void*a, const void *b){ return *(int*)b - *(int*)a;}int maxCoins(int* piles, int pilesSize){ int sum = 0; qsort(piles, pilesSize, 4 ,cmp); // pilesSize / 3 * 2 后面的三分之一都给Bob for(int i = 1;i <= pilesSize /.
2022-02-09 16:41:18
192
原创 2022.2.9-leetcode-1877(贪心)
题目:代码:int cmp(const void* a, const void* b){ return *(int*)a - *(int*)b;}int minPairSum(int* nums, int numsSize){ int n = numsSize / 2; qsort(nums, numsSize, 4, cmp); int sum = nums[n - 1] + nums[n]; while(n--){ sum = s
2022-02-09 16:28:08
537
原创 2022.2.8-leetcode-1403(贪心)
题目:代码:解题思路:题目描述子序列是一个很难实现的东西(不连续的情况),为简便,考虑降序排序A = {a0, a1, a2,.....,ai, ..., an} (a0 > a1 > a2 > .... > ai ... > an)考虑降序是因为题目要求的是“大” ----->要想子序列尽量短 就必须要子序列包含的元素尽量大若存在一个子数列A1= {a0, a1, a2, ..., ai} 满足sum(a) > (sum(...
2022-02-08 17:01:02
361
原创 2022.2.7-leetcode-561(贪心)
题目:代码:题解:先排序再取较小者证明:对于A = [a1, a2, a3……an……a(2n)] 任意分成n对 {(b1, c1), (b2, c2), (b3, c3),……,(bn, cn)}, 取B = {b1, b2, b3, ……,bn}, C = {c1, c2, c3,……,cn}。(A、B、C均为降序)存在一种分法 B0 = {a1, a3, a5, ……, a(2n - 1)}证明此分法最优即证:a1 >= b1...
2022-02-07 21:04:56
327
空空如也
空空如也
TA创建的收藏夹 TA关注的收藏夹
TA关注的人