From 15dcd64d26173d40ae64d9f21b9b7937e54a2c94 Mon Sep 17 00:00:00 2001 From: Baoshuo Date: Thu, 16 Jun 2022 11:26:29 +0800 Subject: [PATCH] =?UTF-8?q?P2831=20[NOIP2016=20=E6=8F=90=E9=AB=98=E7=BB=84?= =?UTF-8?q?]=20=E6=84=A4=E6=80=92=E7=9A=84=E5=B0=8F=E9=B8=9F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit https://www.luogu.com.cn/record/77450202 --- Luogu/P2831/P2831.cpp | 69 +++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 69 insertions(+) create mode 100644 Luogu/P2831/P2831.cpp diff --git a/Luogu/P2831/P2831.cpp b/Luogu/P2831/P2831.cpp new file mode 100644 index 00000000..a01277ff --- /dev/null +++ b/Luogu/P2831/P2831.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; +}