[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 ...
随机推荐
- OR1200处理器中Wishbone总线接口模块WB_BIU介绍
下面内容摘自<步步惊芯--软核处理器内部设计分析>一书 WB_BIU模块是OR1200处理器与外部Wishbone总线连接的接口模块.15.1节给出了WB_BIU模块的对外连接关系,并指出 ...
- java正則表達式总结
近期用到的正則表達式 因为近期在做一个android的新闻client.多次用到了正則表達式.因此总结下. 1.使用正則表達式获取Rss资源内的文章内容的图片url 由于在每条新闻浏览的listVie ...
- matlab 时频分析(短时傅里叶变换、STFT)
短时傅里叶变换,short-time fourier transformation,有时也叫加窗傅里叶变换,时间窗口使得信号只在某一小区间内有效,这就避免了传统的傅里叶变换在时频局部表达能力上的不足, ...
- Glide二次封装库的使用
更多代码可以查询本人GitHub:欢迎阅读,star点起来. Glide二次封装库源码 前言 为什么选择Glide? Glide 轻量级 速度快 可以根据所需加载图片的大小自动适配所需分辨率的图 支持 ...
- ErrorSet
1.获取路径的失误: 例子是对一个列表项的悬浮操作: ~(function() { var lists = $(".footer_log>li"); lists.each(f ...
- Knockout 重新绑定注意要点
function ReImport(id) { //点击按钮时调用函数名称, var node = document.getElementById('bindingNode'); //bindingN ...
- hdu 6170
dp: http://blog.csdn.net/qq_28954601/article/details/77484676 #include <bits/stdc++.h> #define ...
- 一起talk C栗子吧(第三十四回:C语言实例--巧用溢出计算最值)
各位看官们.大家好,上一回中咱们说的是巧用移位的样例,这一回咱们说的样例是:巧用溢出计算最值. 闲话休提,言归正转.让我们一起talk C栗子吧! 大家都知道,程序中的变量都有一个取值范围,这个范围也 ...
- Android中的MVP架构初探
说来羞愧,MVP的架构模式已经在Android领域出现一两年了.可是到今天自己才開始Android领域中的MVP架构征程. 闲话不多说,開始吧. 一.架构演变概述 我记得我找第一份工作时,面试官问我& ...
- Android广告轮播图实现
先看效果 第一步,布局 <?xml version="1.0" encoding="utf-8"?> <RelativeLayout xmln ...