1 条题解
-
0
#include <iostream> #include <vector> #include <tuple> std::vector<std::tuple<int, int, int>> findCombinations(int a, int b) { std::vector<std::tuple<int, int, int>> solutions; int k = 2 * b - a; // 关键值,用于方程5x + 3y = k // 如果k为负数,无解 if (k < 0) { return solutions; } // 遍历所有可能的大骡子数量x for (int x = 0; x <= k / 5; ++x) { int remainder = k - 5 * x; // 如果remainder为负,提前终止循环 if (remainder < 0) { break; } // 检查remainder是否能被3整除 if (remainder % 3 != 0) { continue; } int y = remainder / 3; // 中骡子数量 int z = a - x - y; // 小骡子数量 // 检查z是否为非负偶数 if (z >= 0 && z % 2 == 0) { solutions.push_back(std::make_tuple(x, y, z)); } } return solutions; } int main() { int a, b; std::cin >> a; std::cin >> b; auto combinations = findCombinations(a, b); for (const auto& comb : combinations) { int x = std::get<0>(comb); int y = std::get<1>(comb); int z = std::get<2>(comb); std::cout << x << " " << y << " " << z << std::endl; } return 0; }
- 1
信息
- ID
- 132
- 时间
- 1000ms
- 内存
- 256MiB
- 难度
- 3
- 标签
- (无)
- 递交数
- 48
- 已通过
- 27
- 上传者