1
0
Fork 0
You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
大蒟蒻 920a583abc
Wed, 11 Mar 2020 19:37:48 +0800
6 years ago
..
.vscode Wed, 11 Mar 2020 19:37:48 +0800 6 years ago
CMakeLists.txt Wed, 11 Mar 2020 19:37:48 +0800 6 years ago
Partition.txt Wed, 11 Mar 2020 19:37:48 +0800 6 years ago
PartitionPerf.h Wed, 11 Mar 2020 19:37:48 +0800 6 years ago
PartitionTest.cpp Wed, 11 Mar 2020 19:37:48 +0800 6 years ago
YourFib.h Wed, 11 Mar 2020 19:37:48 +0800 6 years ago
YourPartition.h Wed, 11 Mar 2020 19:37:48 +0800 6 years ago
hw1Test.cpp Wed, 11 Mar 2020 19:37:48 +0800 6 years ago
hw1_2.xlsx Wed, 11 Mar 2020 19:37:48 +0800 6 years ago
readme.txt Wed, 11 Mar 2020 19:37:48 +0800 6 years ago

readme.txt

This file contains ambiguous Unicode characters!

This file contains ambiguous Unicode characters that may be confused with others in your current locale. If your use case is intentional and legitimate, you can safely ignore this warning. Use the Escape button to highlight these characters.

Value:
void Fib::Value(const int &n) //计算并设置斐波那契数列第n项的值value
{
    int a = 0, b = 1;
    for (int i = 0; i < n; i++)
    {
        int t = a + b;
        a = b, b = t;
    }
    value = a;
}
时间复杂度O(n),空间复杂度O(1)。
有基于矩阵快速幂的O(logn)做法,
然而在结果在int范围内的情况下常数较大
这里不列出了。

Partition:
int Partition(int x[], int n, int &movenum, int &compnum, int &bytesnum)
{
    bytesnum = 2 * sizeof(int);
    int i = 0;
    for (int j = 1; j < n; j++)
    {
        compnum++;
        if (x[j] < x[0])
            swap(x, ++i, j), movenum += 3;
    }
    swap(x, 0, i), movenum += 3;
    return i;
}
时间复杂度O(n),空间复杂度O(1)。
将整个数组就地分成大于x[0]和小于x[0]的两部分。