Compare commits
No commits in common. "572479248dec71f65e08ab9642612d260448bc5a" and "a09362480af53318f0f5b76be8da54fa43de75ce" have entirely different histories.
572479248d
...
a09362480a
@ -1,15 +0,0 @@
|
|||||||
//
|
|
||||||
// Created by xfj12 on 2025/3/26.
|
|
||||||
//
|
|
||||||
|
|
||||||
#ifndef INC_2829_H
|
|
||||||
#define INC_2829_H
|
|
||||||
#ifdef __cplusplus
|
|
||||||
extern "C"
|
|
||||||
{
|
|
||||||
#endif
|
|
||||||
int minimumSum(int n, int k);
|
|
||||||
#ifdef __cplusplus
|
|
||||||
}
|
|
||||||
#endif
|
|
||||||
#endif // INC_2829_H
|
|
@ -1,18 +0,0 @@
|
|||||||
//
|
|
||||||
// Created by xfj12 on 2025/3/25.
|
|
||||||
//
|
|
||||||
|
|
||||||
#ifndef INC_2974_H
|
|
||||||
#define INC_2974_H
|
|
||||||
#ifdef __cplusplus
|
|
||||||
extern "C"
|
|
||||||
{
|
|
||||||
#endif
|
|
||||||
/**
|
|
||||||
* Note: The returned array must be malloced, assume caller calls free().
|
|
||||||
*/
|
|
||||||
int *numberGame(int *nums, int numsSize, int *returnSize);
|
|
||||||
#ifdef __cplusplus
|
|
||||||
}
|
|
||||||
#endif
|
|
||||||
#endif // INC_2974_H
|
|
31
src/2829.c
31
src/2829.c
@ -1,31 +0,0 @@
|
|||||||
//
|
|
||||||
// Created by xfj12 on 2025/3/26.
|
|
||||||
//
|
|
||||||
#include <solution/2829.h>
|
|
||||||
#include <stdbool.h>
|
|
||||||
#include <stdlib.h>
|
|
||||||
|
|
||||||
int minimumSum(int n, int k)
|
|
||||||
{
|
|
||||||
int *KAvoid = malloc(sizeof(int) * n);
|
|
||||||
int idx = 1;
|
|
||||||
KAvoid[0] = 1;
|
|
||||||
|
|
||||||
int sum = 0;
|
|
||||||
|
|
||||||
for (int i = 2; idx < n; i++)
|
|
||||||
{
|
|
||||||
bool flag = true;
|
|
||||||
for (int j = 0; j < idx && flag; j++)
|
|
||||||
if (KAvoid[j] + i == k)
|
|
||||||
flag = false;
|
|
||||||
if (flag)
|
|
||||||
KAvoid[idx++] = i;
|
|
||||||
}
|
|
||||||
|
|
||||||
for (int i = 0; i < n; i++)
|
|
||||||
sum += KAvoid[i];
|
|
||||||
|
|
||||||
free(KAvoid);
|
|
||||||
return sum;
|
|
||||||
}
|
|
52
src/2974.c
52
src/2974.c
@ -1,52 +0,0 @@
|
|||||||
//
|
|
||||||
// Created by xfj12 on 2025/3/25.
|
|
||||||
//
|
|
||||||
#include <solution/2974.h>
|
|
||||||
#include <stdio.h>
|
|
||||||
#include <stdlib.h>
|
|
||||||
|
|
||||||
int findMinElement(int *nums, int numsSize, int *returnIndex)
|
|
||||||
{
|
|
||||||
int min = nums[0];
|
|
||||||
*returnIndex = 0;
|
|
||||||
for (int i = 1; i < numsSize; ++i)
|
|
||||||
{
|
|
||||||
if (nums[i] < min)
|
|
||||||
{
|
|
||||||
min = nums[i];
|
|
||||||
*returnIndex = i;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return min;
|
|
||||||
}
|
|
||||||
|
|
||||||
void removeElement(int *nums, int numsSize, int idx)
|
|
||||||
{
|
|
||||||
for (int i = idx; i < numsSize - 1; ++i)
|
|
||||||
nums[i] = nums[i + 1];
|
|
||||||
}
|
|
||||||
|
|
||||||
int *numberGame(int *nums, int numsSize, int *returnSize)
|
|
||||||
{
|
|
||||||
int *result = malloc(sizeof(int) * numsSize);
|
|
||||||
*returnSize = 0;
|
|
||||||
|
|
||||||
while (numsSize > 0)
|
|
||||||
{
|
|
||||||
int aliceIndex;
|
|
||||||
const int alice = findMinElement(nums, numsSize, &aliceIndex);
|
|
||||||
removeElement(nums, numsSize--, aliceIndex);
|
|
||||||
|
|
||||||
int bobIndex;
|
|
||||||
const int bob = findMinElement(nums, numsSize, &bobIndex);
|
|
||||||
removeElement(nums, numsSize--, bobIndex);
|
|
||||||
|
|
||||||
result[(*returnSize)++] = bob;
|
|
||||||
result[(*returnSize)++] = alice;
|
|
||||||
}
|
|
||||||
|
|
||||||
for (int i = 0; i < numsSize; ++i)
|
|
||||||
printf("%d ", result[i]);
|
|
||||||
|
|
||||||
return result;
|
|
||||||
}
|
|
@ -1,16 +0,0 @@
|
|||||||
#include <gtest/gtest.h>
|
|
||||||
#include <solution/2829.h>
|
|
||||||
|
|
||||||
TEST(MinimumSumTest, Test1)
|
|
||||||
{
|
|
||||||
int n = 5, k = 4;
|
|
||||||
int expected = 18;
|
|
||||||
EXPECT_EQ(minimumSum(n, k), expected);
|
|
||||||
}
|
|
||||||
|
|
||||||
TEST(MinimumSumTest, Test2)
|
|
||||||
{
|
|
||||||
int n = 2, k = 6;
|
|
||||||
int expected = 3;
|
|
||||||
EXPECT_EQ(minimumSum(n, k), expected);
|
|
||||||
}
|
|
@ -1,38 +0,0 @@
|
|||||||
#include <gtest/gtest.h>
|
|
||||||
#include <solution/2974.h>
|
|
||||||
|
|
||||||
TEST(NumberGameTest, Test1)
|
|
||||||
{
|
|
||||||
int nums[] = {5, 4, 2, 3};
|
|
||||||
int numsSize = sizeof(nums) / sizeof(nums[0]);
|
|
||||||
int returnSize = 0;
|
|
||||||
|
|
||||||
int *result = numberGame(nums, numsSize, &returnSize);
|
|
||||||
|
|
||||||
int expected[] = {3, 2, 5, 4};
|
|
||||||
ASSERT_EQ(returnSize, 4);
|
|
||||||
for (int i = 0; i < returnSize; ++i)
|
|
||||||
{
|
|
||||||
EXPECT_EQ(result[i], expected[i]);
|
|
||||||
}
|
|
||||||
|
|
||||||
free(result);
|
|
||||||
}
|
|
||||||
|
|
||||||
TEST(NumberGameTest, Test2)
|
|
||||||
{
|
|
||||||
int nums[] = {2, 5};
|
|
||||||
int numsSize = sizeof(nums) / sizeof(nums[0]);
|
|
||||||
int returnSize = 0;
|
|
||||||
|
|
||||||
int *result = numberGame(nums, numsSize, &returnSize);
|
|
||||||
|
|
||||||
int expected[] = {5, 2};
|
|
||||||
ASSERT_EQ(returnSize, 2);
|
|
||||||
for (int i = 0; i < returnSize; ++i)
|
|
||||||
{
|
|
||||||
EXPECT_EQ(result[i], expected[i]);
|
|
||||||
}
|
|
||||||
|
|
||||||
free(result);
|
|
||||||
}
|
|
Loading…
x
Reference in New Issue
Block a user