QOJ.ac

QOJ

时间限制: 1.0 s 内存限制: 512 MB 总分: 100

#10956. 垫圈

统计

你有 $n$ 件衣服和一个洗衣机。洗衣机足够大,可以一次洗完所有的衣服。然而,我们需要担心颜色转移问题:如果我们把不同颜色的衣服放在一起洗,一种颜色的染料可能会沾染到另一种颜色上。具体来说,设 $r_i, g_i, b_i$ 分别表示第 $i$ 件衣服的红、绿、蓝颜色分量。当 $n$ 件衣服一起洗时,颜色转移 $c$ 定义为:

$$c = \sum_{i=1}^{n} ((r_i - \bar{r})^2 + (g_i - \bar{g})^2 + (b_i - \bar{b})^2)$$

其中 $\bar{r}, \bar{g}, \bar{b}$ 分别是 $r_i, g_i, b_i$ 的平均值。第 $i$ 件衣服的颜色信息可以看作是三维 RGB 空间中的一个点 $(r_i, g_i, b_i)$。你可以假设在 RGB 空间中,任意三点(衣服)不共线,且任意四点(衣服)不共面。

洗衣机消耗大量电力,你必须将 $n$ 件衣服分成最多 $k$ 组,并对每一组分别运行洗衣机。总颜色转移量是每一组颜色转移量之和。给定 $n$ 件衣服的颜色信息和 $k$,编写一个程序来计算最小的总颜色转移量。

输入格式

程序从标准输入读取数据。第一行包含两个整数 $n$ ($1 \le n \le 100$) 和 $k$ ($1 \le k \le 2$)。在接下来的 $n$ 行中,第 $i$ 行包含三个整数 $r_i, g_i, b_i$ ($0 \le r_i, g_i, b_i \le 1,000$)。

输出格式

程序将结果写入标准输出。输出一行,包含最小的总颜色转移量,保留到小数点后六位。

样例

样例输入 1

2 1
36 16 85
74 87 38

样例输出 1

4347.000000

样例输入 2

1 2
12 26 90

样例输出 2

0.000000

样例输入 3

3 2
93 50 26
40 0 77
99 10 29

样例输出 3

822.500000

Discussions

About Discussions

The discussion section is only for posting: General Discussions (problem-solving strategies, alternative approaches), and Off-topic conversations.

This is NOT for reporting issues! If you want to report bugs or errors, please use the Issues section below.

Open Discussions 0
No discussions in this category.

Issues

About Issues

If you find any issues with the problem (statement, scoring, time/memory limits, test cases, etc.), you may submit an issue here. A problem moderator will review your issue.

Guidelines:

  1. This is not a place to publish discussions, editorials, or requests to debug your code. Issues are only visible to you and problem moderators.
  2. Do not submit duplicated issues.
  3. Issues must be filed in English or Chinese only.
Active Issues 0
No issues in this category.
Closed/Resolved Issues 0
No issues in this category.