Color me less

本文介绍了一个基于欧几里得距离的颜色映射问题解决方案。该方案使用C语言实现,旨在将RGB颜色空间中的任意颜色映射到一个预定义的16种目标颜色之一,通过计算每种目标颜色与待映射颜色之间的距离来确定最接近的目标颜色。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

Color Me Less
Time Limit: 1000MS
Memory Limit: 10000K
Total Submissions: 26432
Accepted: 12740
Description

A color reduction is a mapping from a set of discrete colors to a smaller one. The solution to this problem requires that you perform just such a mapping in a standard twenty-four bit RGB color space. The input consists of a target set of sixteen RGB color values, and a collection of arbitrary RGB colors to be mapped to their closest color in the target set. For our purposes, an RGB color is defined as an ordered triple (R,G,B) where each value of the triple is an integer from 0 to 255. The distance between two colors is defined as the Euclidean distance between two three-dimensional points. That is, given two colors (R1,G1,B1) and (R2,G2,B2), their distance D is given by the equation

Input

The input is a list of RGB colors, one color per line, specified as three integers from 0 to 255 delimited by a single space. The first sixteen colors form the target set of colors to which the remaining colors will be mapped. The input is terminated by a line containing three -1 values.
Output

For each color to be mapped, output the color and its nearest color from the target set.

If there are more than one color with the same smallest distance, please output the color given first in the color set.
Sample Input

0 0 0
255 255 255
0 0 1
1 1 1
128 0 0
0 128 0
128 128 0
0 0 128
126 168 9
35 86 34
133 41 193
128 0 128
0 128 128
128 128 128
255 0 0
0 1 0
0 0 0
255 255 255
253 254 255
77 79 134
81 218 0
-1 -1 -1
Sample Output

(0,0,0) maps to (0,0,0)
(255,255,255) maps to (255,255,255)
(253,254,255) maps to (255,255,255)
(77,79,134) maps to (128,128,128)
(81,218,0) maps to (126,168,9)

#include<stdio.h>
int main()
    {
    int save[17][4];
    int clo[4];
    int n,i;
    for(i=1;i<=16;i++)
    {
        for(n=1;n<=3;n++)
        scanf("%d",&save[i][n]);
    }

    while(1)
    {
        int ne[3];
        scanf("%d %d %d",&ne[1],&ne[2],&ne[3]);
        if(ne[1]==-1&&ne[2]==-1&&ne[3]==-1)
        break;
        int min=3*255*255;
        for(i=1;i<=16;i++)
        {
            int d;
            d=(save[i][1]-ne[1])*(save[i][1]-ne[1])+(save[i][2]-ne[2])*(save[i][2]-ne[2])+(save[i][3]-ne[3])*(save[i][3]-ne[3]);
            if(d<min)
            {
            min=d;
            clo[1]=save[i][1];
            clo[2]=save[i][2];
            clo[3]=save[i][3];
            }
        }
        printf("(%d,%d,%d) maps to (%d,%d,%d)\n",ne[1],ne[2],ne[3],clo[1],clo[2],clo[3]);

    }

    return 0;

}

这道题完全使用c语言的简单基本知识来写,在写的过程中还是因为数组容量的问题发生了一些错误,数组的容量因为包括第0个数组,所以一般到n-1个结束,这道题因为我一开始定义save[16][3],结果变成ne maps to ne,目前还不知道为什么会有这种错误产生,而不是其他数值,等待解决

### 如何使用 `module.less` 文件进行 CSS 模块化配置 为了实现 CSS 模块化的功能,在 Vite 项目中的 `vite.config.js` 中可以按照如下方式进行设置: #### 修改 vite.config.js 配置文件 通过编辑项目的根目录下的 `vite.config.js` 来启用 CSS 模块化以及 LESS 的预处理器选项。具体来说,可以在 `css.modules` 下定义模块化规则,并在 `preprocessorOptions` 中指定针对特定预处理语言(如LESS)的额外参数。 ```javascript import { defineConfig } from 'vite'; export default defineConfig({ css: { modules: { generateScopedName: '[name]__[local]___[hash:base64:5]', hashPrefix: 'prefix', }, preprocessorOptions: { less: { javascriptEnabled: true, } } } }); ``` 此段代码设置了当遇到 `.module.less` 结尾的文件时会应用上述规则来生成唯一的类名并允许在 Less 文件里嵌入 JavaScript 表达式[^1]。 #### 创建 module.less 文件 创建一个新的名为 `style.module.less` 或者其他你喜欢的名字作为样式表文件。注意这里要加上 `.module.` 前缀以便让 Webpack 知道这是一个 CSS Module 文件而不是普通的全局样式文件。 在这个例子中,假设有一个按钮组件需要自定义样式,则可在该文件中编写如下内容: ```less // style.module.less .button { background-color: blue; color: white; &__text { font-size: 18px; } &:hover { opacity: .9; } } ``` #### 使用 module.less 文件内的样式 最后一步是在 React 组件或其他前端框架组件中引入这个新的样式文件,并像对象属性一样访问其导出的选择器名称。例如在一个简单的 React 函数式组件中这样写: ```jsx import styles from './style.module.less'; function Button() { return ( <button className={styles.button}> <span className={styles['button__text']}>Click Me</span> </button> ); } export default Button; ``` 这样做之后,所有的类名都会被自动转换成独一无二的形式,从而防止不同组件之间的冲突问题发生[^2]。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值