From e69372308697273bd48d9fe42ea6692b1a54233f Mon Sep 17 00:00:00 2001 From: Baoshuo Date: Thu, 16 Jun 2022 17:19:24 +0800 Subject: [PATCH] =?UTF-8?q?524.=20=E6=84=A4=E6=80=92=E7=9A=84=E5=B0=8F?= =?UTF-8?q?=E9=B8=9F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit https://www.acwing.com/problem/content/submission/code_detail/14784204/ --- AcWing/524/524.cpp | 69 ++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 69 insertions(+) create mode 100644 AcWing/524/524.cpp diff --git a/AcWing/524/524.cpp b/AcWing/524/524.cpp new file mode 100644 index 00000000..a01277ff --- /dev/null +++ b/AcWing/524/524.cpp @@ -0,0 +1,69 @@ +#include +#include + +using std::cin; +using std::cout; +const char endl = '\n'; + +const int N = 20; +const double eps = 1e-6; + +int t, n, m, cnt, f[1 << N], s[N << 4]; +std::pair points[N]; + +inline std::pair e(const std::pair &_a, const std::pair &_b) { + return std::make_pair( + (_a.second - _b.second * _a.first / _b.first) / (_a.first * (_a.first - _b.first)), + (_a.second - _b.second * _a.first * _a.first / (_b.first * _b.first)) / (_a.first - _a.first * _a.first / _b.first)); +} + +int main() { + std::ios::sync_with_stdio(false); + cin.tie(nullptr); + + cin >> t; + + while (t--) { + cnt = 0; + memset(f, 0x3f, sizeof(f)); + memset(s, 0x00, sizeof(s)); + + cin >> n >> m; + + for (int i = 0; i < n; i++) { + cin >> points[i].first >> points[i].second; + } + + for (int i = 0; i < n; i++) { + for (int j = i + 1; j < n; j++) { + if (std::abs(points[i].first - points[j].first) < eps) continue; + + auto r = e(points[i], points[j]); + if (r.first > -eps) continue; + + cnt++; + for (int k = 0; k < n; k++) { + if (std::abs(r.first * points[k].first * points[k].first + r.second * points[k].first - points[k].second) < eps) { + s[cnt] |= 1 << k; + } + } + } + } + + f[0] = 0; + for (int i = 0; i < 1 << n; i++) { + // 两只及以上 + for (int j = 1; j <= cnt; j++) { + f[i | s[j]] = std::min(f[i | s[j]], f[i] + 1); + } + // 一只 + for (int j = 0; j < n; j++) { + f[i | 1 << j] = std::min(f[i | 1 << j], f[i] + 1); + } + } + + cout << f[(1 << n) - 1] << endl; + } + + return 0; +}