From 8033906aa27937452a582855c679b01d908e5d06 Mon Sep 17 00:00:00 2001 From: Baoshuo Date: Mon, 6 Jun 2022 14:51:29 +0800 Subject: [PATCH] =?UTF-8?q?P3265=20[JLOI2015]=E8=A3=85=E5=A4=87=E8=B4=AD?= =?UTF-8?q?=E4=B9=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit https://www.luogu.com.cn/record/77017776 --- Luogu/P3265/P3265.cpp | 76 +++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 76 insertions(+) create mode 100644 Luogu/P3265/P3265.cpp diff --git a/Luogu/P3265/P3265.cpp b/Luogu/P3265/P3265.cpp new file mode 100644 index 00000000..2596f854 --- /dev/null +++ b/Luogu/P3265/P3265.cpp @@ -0,0 +1,76 @@ +#include +#include + +using std::cin; +using std::cout; +const char endl = '\n'; + +const int N = 505; +const double eps = 1e-4; + +int n, m, ans, sum; +double p[N][N]; + +struct node { + int w; + double v[N]; + + double& operator[](const int& _i) { + return v[_i]; + } + + bool operator<(const node& _y) const { + return w < _y.w; + } +} q[N]; + +inline bool insert(double* a) { + for (int i = 1; i <= m; i++) { + if (std::abs(a[i]) > eps) { + if (std::abs(p[i][i]) > eps) { // > 0 + double k = a[i] / p[i][i]; + for (int j = i; j <= m; j++) { + a[j] -= k * p[i][j]; + } + } else { + for (int j = i; j <= m; j++) { + p[i][j] = a[j]; + } + + return true; + } + } + } + + return false; +} + +int main() { + std::ios::sync_with_stdio(false); + cin.tie(nullptr); + + cin >> n >> m; + + for (int i = 1; i <= n; i++) { + for (int j = 1; j <= m; j++) { + cin >> q[i][j]; + } + } + + for (int i = 1; i <= n; i++) { + cin >> q[i].w; + } + + std::sort(q + 1, q + 1 + n); + + for (int i = 1; i <= n; i++) { + if (insert(q[i].v)) { + ans++; + sum += q[i].w; + } + } + + cout << ans << ' ' << sum << endl; + + return 0; +}