[ACM] POJ 1046 Color Me Less
Time Limit: 1000MS | Memory Limit: 10000K | |
Total Submissions: 30146 | Accepted: 14634 |
Description
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 terminated by a line containing three -1 values.
Output
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)
Source
解题思路:
一种颜色用三元组(r,g,b)表示。两个颜色的距离为。
给出16个已知的颜色值,求这里面距离给定的颜色值距离最短的颜色值。
枚举,比較距离就能够了。
代码:
#include <iostream>
#include <cmath>
const int inf=0x7fffffff;
using namespace std; struct RGB
{
double r,g,b;
int match;//用来记录距离最短的颜色是第几个
}rgb[100]; int main()
{
int k=1;
while(cin>>rgb[k].r>>rgb[k].g>>rgb[k].b&&rgb[k].r!=-1&&rgb[k].g!=-1&&rgb[k].b!=-1)
{
k++;
}
double dis;
for(int i=17;i<=k-1;i++)
{
dis=inf;
for(int j=16;j>=1;j--)
{
double temp=sqrt((rgb[i].r-rgb[j].r)*(rgb[i].r-rgb[j].r)+(rgb[i].g-rgb[j].g)*(rgb[i].g-rgb[j].g)+(rgb[i].b-rgb[j].b)*(rgb[i].b-rgb[j].b));
if(dis>=temp)
{
dis=temp;//最短距离
rgb[i].match=j;//第i中颜色距离第j种颜色距离最短
}
}
}
for(int i=17;i<=k-1;i++)
{
cout<<"("<<rgb[i].r<<","<<rgb[i].g<<","<<rgb[i].b<<") maps to ("<<rgb[rgb[i].match].r<<","<<rgb[rgb[i].match].g<<","<<rgb[rgb[i].match].b<<")"<<endl; }
return 0;
}
[ACM] POJ 1046 Color Me Less的更多相关文章
- POJ 1046 Color Me Less 最详细的解题报告
题目来源:POJ 1046 Color Me Less 题目大意:每一个颜色由R.G.B三部分组成,D=Math.sqrt(Math.pow((left.red - right.red), 2)+ M ...
- poj 1046 ——Color Me Less
提交地址:http://poj.org/problem?id=1046 Color Me Less Time Limit: 1000MS Memory Limit: 10000K Total Su ...
- [ACM] POJ 2154 Color (Polya计数优化,欧拉函数)
Color Time Limit: 2000MS Memory Limit: 65536K Total Submissions: 7630 Accepted: 2507 Description ...
- poj 1046 Color Me Less
Color Me Less Time Limit: 1000MS Memory Limit: 10000K Total Submissions: 33007 Accepted: 16050 D ...
- POJ 1046 Color Me Less(浅水)
一.Description A color reduction is a mapping from a set of discrete colors to a smaller one. The sol ...
- 北大ACM - POJ试题分类(转自EXP)
北大ACM - POJ试题分类 -- By EXP 2017-12-03 转载请注明出处: by EXP http://exp-blog.com/2018/06/28/pid-38/ 相关推荐文: 旧 ...
- ACM: POJ 1401 Factorial-数论专题-水题
POJ 1401 Factorial Time Limit:1500MS Memory Limit:65536KB 64bit IO Format:%lld & %llu ...
- 组合数学 - 波利亚定理 --- poj : 2154 Color
Color Time Limit: 2000MS Memory Limit: 65536K Total Submissions: 7873 Accepted: 2565 Description ...
- [ACM] POJ 3687 Labeling Balls (拓扑排序,反向生成端)
Labeling Balls Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 10161 Accepted: 2810 D ...
随机推荐
- rev---将文件中的每行内容以字符为单位反序输出
rev命令将文件中的每行内容以字符为单位反序输出,即第一个字符最后输出,最后一个字符最先输出,依次类推.
- PHP CURL HTTPS POST
PHP CURL HTTPS POST function vpost($url,$data){ // 模拟提交数据函数 $curl = curl_init(); // 启动一个CURL会话 ...
- 洛谷——P1027 Car的旅行路线
https://www.luogu.org/problem/show?pid=1027#sub 题目描述 又到暑假了,住在城市A的Car想和朋友一起去城市B旅游.她知道每个城市都有四个飞机场,分别位于 ...
- NStimer 被堵塞
我们在界面上滚动一个scrollview,那么我们会发如今停止滚动前,会发现NSTimer未被运行.就好像scrollView在滚动的时候将timer暂停了一样,在查看对应文档后发现,这事实上就是ru ...
- 第二天,导出文件sql,查询,视图view,聚合函数,反模式,字符串处理函数
//把数据库导出到脚本文件mysqldump -uroot -p1234 --databases abc > d:/a/abc.sql CREATE TABLE stud( id INT PRI ...
- Vue v-bind的使用
1.src <!DOCTYPE html> <html> <head> <meta charset="utf-8"> <tit ...
- RTSP、HTTP、HTTPS、SDP四种协议详解
我们将主要讲解RTSP,HTTP,HTTPS, SDP四种协议. 一:RTSP协议简介 实时流协议RTSP是一个应用层协议,用于控制具有实时特性的数据(例如多媒体流)的传送. RTSP协议一般与RT ...
- js关于循环的理解
学习任何语言都离不开循环,js也是一样,看了网上的资料,整理一份关于js循环的理解. 1.最基础循环,js和其他高级语言一样使用for.while循环 (function() { for(var i= ...
- IIS文件上传大小修改配置说明
原因:Web 服务器上的请求筛选被配置为拒绝该请求,因为内容长度超过配置的值(IIS 7 默认文件上传大小时30M). 解决:IIS7更改asp.net文件上传大小限制 步骤如下: 1. 修改I ...
- C_数组详解
数组: 一 一维数组 1.1 一维数组的定义: 类型符 数组名[常量表达式]; int a[10]; 说明: 1.数组的命名规则遵循标识符命名规则. 2.定义时需要指定元素的个数.方括号里的常量表达式 ...