some programs!!
This commit is contained in:
1 parent
ed054247d5
commit
71f1022dea
38 files changed
+1037
-281
No files matched your search
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
@@ -0,0 +1,54 @@
|
||||
#include <algorithm>
|
||||
#include <iostream>
|
||||
#include <vector>
|
||||
#include <cmath>
|
||||
|
||||
struct PerfectCubeNumber {
|
||||
int num = 0;
|
||||
std::tuple<int, int, int> children;
|
||||
|
||||
constexpr bool operator<(const PerfectCubeNumber& other) const {
|
||||
return std::tie(num, children) < std::tie(other.num, other.children);
|
||||
}
|
||||
};
|
||||
|
||||
constexpr int MAX_N = 101;
|
||||
std::vector<PerfectCubeNumber> perfect_cube_numbers;
|
||||
int n;
|
||||
|
||||
constexpr int cubes_sum(int a, int b, int c) {
|
||||
return a * a * a + b * b * b + c * c * c;
|
||||
}
|
||||
|
||||
void init_numbers() {
|
||||
for (int a = 2; a < MAX_N; a++) {
|
||||
for (int b = a; b < MAX_N; b++) {
|
||||
for (int c = b; ; c++) {
|
||||
const int x_cube = cubes_sum(a, b, c);
|
||||
if (x_cube > MAX_N * MAX_N * MAX_N) { break; }
|
||||
for (int x = std::floor(std::cbrt(x_cube)), i = 0; i < 3; x++, i++) {
|
||||
if (x * x * x == x_cube) {
|
||||
perfect_cube_numbers.push_back({x, std::tuple(a, b, c)});
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
std::sort(perfect_cube_numbers.begin(), perfect_cube_numbers.end());
|
||||
}
|
||||
|
||||
int main() {
|
||||
std::ios::sync_with_stdio(false);
|
||||
std::cin.tie(nullptr);
|
||||
|
||||
init_numbers();
|
||||
|
||||
std::cin >> n;
|
||||
for (const auto [num, children] : perfect_cube_numbers) {
|
||||
if (num > n) { break; }
|
||||
auto [a,b,c] = children;
|
||||
std::cout << "Cube = " << num << ", Triple = (" << a << "," << b << "," << c << ")" << std::endl;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
@@ -0,0 +1,31 @@
|
||||
#include <iostream>
|
||||
#include <array>
|
||||
|
||||
constexpr int MAX_N = 21;
|
||||
|
||||
// 编译期生成斐波那契数列
|
||||
constexpr std::array<int, MAX_N> make_fib() {
|
||||
std::array<int, MAX_N> fib{}; // 零初始化
|
||||
fib[0] = 1;
|
||||
fib[1] = 1;
|
||||
for (int i = 2; i < MAX_N; ++i) {
|
||||
fib[i] = fib[i - 1] + fib[i - 2];
|
||||
}
|
||||
return fib;
|
||||
}
|
||||
|
||||
static constexpr auto fib = make_fib();
|
||||
|
||||
int x;
|
||||
|
||||
int main() {
|
||||
std::ios::sync_with_stdio(false);
|
||||
std::cin.tie(nullptr);
|
||||
|
||||
std::cin >> x;
|
||||
while (std::cin >> x) {
|
||||
std::cout << fib[x - 1] << std::endl;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
@@ -0,0 +1,17 @@
|
||||
def solve(n: int) -> int:
|
||||
balloons = [i for i in range(1, n + 1)]
|
||||
while True:
|
||||
deleted_amount = 0
|
||||
for x in range(1, n):
|
||||
if len(balloons) <= x * x - deleted_amount - 1 or len(balloons) == 1:
|
||||
break
|
||||
del balloons[x * x - deleted_amount - 1]
|
||||
deleted_amount += 1
|
||||
if len(balloons) == 1:
|
||||
break
|
||||
return balloons[0]
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
for n in range(1, 1150):
|
||||
print(n, "->", solve(n))
|
||||
@@ -0,0 +1,26 @@
|
||||
/*
|
||||
* 本来想打表的,打着打着发现了一些数学规律。具体怎么证明嘛……🤷
|
||||
*/
|
||||
|
||||
#include <iostream>
|
||||
#include <cmath>
|
||||
|
||||
constexpr size_t MAX_N = 10001;
|
||||
|
||||
int get_ans(int n) {
|
||||
const int k = ceil(-0.5 + 0.5 * sqrt(4 * n + 1));
|
||||
const bool extra = k * k < n;
|
||||
const int ans = k * (k - 1) + 1 + k * extra;
|
||||
return ans;
|
||||
}
|
||||
|
||||
int main() {
|
||||
std::ios::sync_with_stdio(false);
|
||||
std::cin.tie(nullptr);
|
||||
|
||||
int n;
|
||||
std::cin >> n;
|
||||
std::cout << get_ans(n) << std::endl;
|
||||
|
||||
return 0;
|
||||
}
|
||||
Reference in new issue
Block a user