From af265431c4377fcf939e7f83df773270917f53f8 Mon Sep 17 00:00:00 2001 From: Baoshuo Date: Tue, 27 Sep 2022 10:43:22 +0800 Subject: [PATCH] =?UTF-8?q?P2503=20[HAOI2006]=E5=9D=87=E5=88=86=E6=95=B0?= =?UTF-8?q?=E6=8D=AE?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit https://www.luogu.com.cn/record/87697641 --- Luogu/P2503/P2503.cpp | 45 +++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 45 insertions(+) create mode 100644 Luogu/P2503/P2503.cpp diff --git a/Luogu/P2503/P2503.cpp b/Luogu/P2503/P2503.cpp new file mode 100644 index 00000000..3eb7ca3e --- /dev/null +++ b/Luogu/P2503/P2503.cpp @@ -0,0 +1,45 @@ +#include +#include +#include +#include +#include +#include +#include + +using std::cin; +using std::cout; +const char endl = '\n'; + +int main() { + std::ios::sync_with_stdio(false); + cin.tie(nullptr); + + int n, m; + double ans = 1e9; + std::mt19937 rng(std::random_device{}()); + + cin >> n >> m; + + std::vector a(n); + + for (int& x : a) cin >> x; + + for (int i = 0; i < 1000000; i++) { + std::vector b(m); + + std::shuffle(a.begin(), a.end(), rng); + + for (int x : a) { + *std::min_element(b.begin(), b.end()) += x; + } + + double avg = static_cast(std::accumulate(b.begin(), b.end(), 0)) / m; + double variance = std::sqrt(std::accumulate(b.begin(), b.end(), 0.0, [&](double sum, int x) { return sum + std::pow(avg - x, 2); }) / m); + + ans = std::min(ans, variance); + } + + cout << std::fixed << std::setprecision(2) << ans << endl; + + return 0; +}