ZOJ_1067_Color Me Less

3分钟!教会你用 DeepSeek/Claude3.7+Cursor 快速入门AI编程(喂饭级教程) 阅读详情
Color Me Less

Time Limit: 2 Seconds      Memory Limit: 65536 KB

Problem

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

The input file 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.


Example

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

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: Greater New York 2001


      鉴于迫切提高英语水平,针对以后的题目,将给出全文翻译,虽然这大大增加了做题需要的时间,但是对自己的提高也有帮助,特此说明,与君共勉!不完善之处请多多指摘。


翻译:

                                                                       程序设计(这题目太难翻,直译总感觉不对,这样翻译取自有道词典。。)

     (这一段引用自他人,特此说明)

      缩色就是将一组不连续的颜色绘制成一个更少颜色的图,解决办法是你需要在24位标准颜色空间里完成这个绘制。输入的值由固定的16RGB颜色值,以及与规定颜色最接近的任何颜色的集合。为了利于我们使用,一个RGB颜色定义为一定的三个数的组(RGB),其中三个数都是0到255之间的整数。两个颜色之间的距离定义为两个三维点之间的欧几里得距离。这就是说,给两个颜色(R1,G1,B1)和 (R2,G2,B2),他们的距离由方程式给出。 
     输入
     输入是一组RGB颜色,每个颜色占据一行,由3个0-255的整型来指明并且3个整型由单个空格来划分开。首先输入的16组颜色是余下的将要绘制的颜色的目标颜色组。输入由包含3个-1值的一行来终止。
     输出
    对于每个要被绘制的颜色,输出他们的颜色以及离他们最近的颜色。




题意和思路:不得不说。。ZOJ把简单题用英语复杂化的水平还是不错的。。一定要加上个缩色的背景。。题目的意思就是先给出16个颜色,再给出5个颜色,从16个颜色当中找到离这5个颜色最近的颜色,打印出来就可以了。


易错点:这个错误我觉得我找出来是运气好。。要不然没这么轻易看出来,之前测试全部正确但是wrong answer其实有个小细节要注意,就是对于有多个目标点和输入的点的距离是相同的时候,要取在前面的目标点


Sample Program Here

#include<iostream>
#include<math.h>
using namespace std;
struct RGB{
   float r;
   float g;
   float b;
};

void calculate(RGB input[],int len1,RGB target[],int len2){
   float distance=0,temp;
   RGB nearest[100]; //记录每个输出对应的最近的点
   


   for(int i=0;i<len1;i++){
	   //计算一次距离公式,初始化distance
	   distance=pow(input[i].r-target[0].r,2)+pow(input[i].g-target[0].g,2)+pow(input[i].b-target[0].b,2);
	   		  nearest[i].r=target[0].r;
			  nearest[i].g=target[0].g;
			  nearest[i].b=target[0].b;
	   for(int j=1;j<len2;j++){
	      temp=pow(input[i].r-target[j].r,2)+pow(input[i].g-target[j].g,2)+pow(input[i].b-target[j].b,2);
		  if(temp<distance){
			  distance=temp;
		      nearest[i].r=target[j].r;
			  nearest[i].g=target[j].g;
			  nearest[i].b=target[j].b;

		  }
	   }

	   //离第2个颜色距离最近的点得到
       cout<<'('<<input[i].r<<','<<input[i].g<<','<<input[i].b<<") maps to "
		   <<'('<<nearest[i].r<<','<<nearest[i].g<<','<<nearest[i].b<<')'<<endl;
   }
}


int main(){
  RGB target[16];
  RGB in[100];
  int i=0;


  //初始化目标颜色组
  for(i=0;i<16;i++){
     cin>>target[i].r>>target[i].g>>target[i].b;
  }


  i=0;
  while(1){
     cin>>in[i].r>>in[i].g>>in[i].b;
	 if(in[i].r==-1&&in[i].g==-1&&in[i].b==-1){
	    calculate(in,i,target,16);  //结束则进行计算
		break;
	 }
	 i++;
  }
  return 0;
}


      



2023年全国青少年信息素养大赛C++编程初中组决赛真题+答案解析 阅读详情

相关推荐

期权定价模型系列[11]三叉树期权定价[trinomial model ]

三叉树期权定价方法简介

xiaowu1997的博客 1847

【ZOJ 1067】Color Me Less 题解(向量+开方)

问题颜色缩减是从一组离散颜色到较小颜色的映射。这个问题的解决方案需要在标准的24位RGB颜色空间中执行这样的映射。输入由十六个RGB颜色值的目标集合和要映射到目标集合中最接近的颜色的任意RGB颜色集合组成。为了我们的目的,RGB颜色被定义为有序三元组(R,G,B),其中三元组的每个值都是从0到255的整数。两种颜色之间的距离被定义为两个三维点之间的欧几里得距离。也就是说,给定两种颜色(R1,G1,B1)和(R2,G2,B2),它们的距离D由下式给出输入。

HEX9CF的技术博客 820

matlab电偶极子源码,电偶极子的MATLAB场模拟

电偶极子周围电场电势分布的MATLAB三维模拟Matlab可以用于模拟四维场的效果,本文以电偶极子的电场和电势场为例展示MATLAB在该方面领域的应用。摘要电偶极子由一个正电荷和一个负电荷组成,其电场和空间电势分布与单电荷相比具有一些重要的特性。本文将给出电场和电势场的近似表达式。这两个量的精确表达式是复杂的,不太常用,因此 MATLAB 被采用来操作精确值和绘制三维分布的远区域, 近区域和一侧区...

weixin_35135480的博客 3150

C语言tzoj1067答案,zoj 1067

输入一组RGB颜色列表,每行一个颜色,是三个从0~255的整数前16行是目标颜色组,-1 -1 -1表示结束16组颜色以后接下来的几行是需要判断的,看它和哪个颜色的距离D最小,找出这个对应的颜色注意空格括弧等等#include#includeusing namespace std;struct Color{int R,G,B;}map[];int main(void){int i,r,g,b,mr...

weixin_34597791的博客 943

LTE信令流程实战:从Attach到Service Request的完整解析(附常见问题排查)

本文深入解析LTE信令流程中的Attach和Service Request关键环节,提供从基础原理到实战排查的完整指南。涵盖鉴权、承载建立等核心步骤,分析常见故障模式及优化方案,并附赠信令跟踪工具使用技巧,助力通信工程师提升网络运维效率。

alpha的博客 319

CTP开发实战:如何高效处理预埋单与委托单的完整流程(附代码示例)

本文深入探讨了CTP开发中预埋单与委托单的完整处理流程,从订单生命周期理解、核心代码实现到异步事件处理与系统健壮性构建。通过详细的代码示例和状态机分析,为开发者提供了构建高可靠订单处理系统的实战指南,重点解决了状态同步、异常恢复等关键工程挑战。

weixin_29234239的博客 116

zoj 1067

Color Me Less Problem A color reduction is a mapping from a set of discrete colors to a smaller one. The solution to this problem requ

924

SolidWorks速成教程P3-6【零件 | 第六节】——草图封闭轮廓&所选轮廓&厚度为零的报错

到这里,我们已经将特征成型的常用功能学完。这节我来继续讲解一下 SolidWorks中建模的一些容易忽略的问题(草图封闭轮廓&所选轮廓&厚度为零的报错)。

嵌入式阿齐Archie 5780

C++ Zoj 1067 Color Me Less

题目大意是: 输入:         先输入16组RGB的值(每行输入一组)         接着输入每组测试数据(RGB的值),以-1 -1 -1结束程序 输出:        先求出测试数据RGB的值与之前的16组目标RGB数据中哪组的D值最小         然后输出这D值最小的组   实现程序: AC #include &lt;iostream&gt; usi...

ChanJose的博客 550

092、Python在芯片验证中的应用:从脚本小子到验证架构师

Python在芯片验证中的高效应用 本文通过实际案例展示了Python在芯片验证中的关键作用。凌晨三点的调试场景揭示了传统方法的局限,Python脚本能在20分钟内分析80GB波形数据定位FIFO指针问题。文章重点介绍了两个核心工具: 智能日志分析系统:通过正则表达式和上下文分析,自动分类百万行验证日志中的错误,生成可视化报告,效率远超传统grep方法。 寄存器模型生成器:将Excel表格自动转换为UVM寄存器模型代码,将原本需要两周的手工工作缩短至两小时,同时保证零错误。 文章还展示了Python与Sys

z534437748的博客 71

Underactuated Robotics - 欠驱动机器人学(一)- 全驱动与欠驱动系统

根据牛顿的观点,机械系统的动力学是二阶的(其状态由位置向量 q(也称为配置向量)和速度向量以及(可能还有)时间给出。二阶控制动力系统的一般形式是:其中 u 是控制向量。定义 1.1 (欠驱动控制微分方程) 二阶控制微分方程描述如下:在状态和时间 t 中,如果所得到的映射是可射的:对于每一个,都存在一个能产生预期响应的,那么系统就是全驱动的。否则,就是欠驱动(状态在时间 t)。

机器人控制与仿真应用 3377

zoj-1067

简单题,写不出,很难受。 为什么写不出呢? 首先看题,知道题意是让16位之后的每一个数与前16个数进行COLOR运算,并输出最小的那个数。 一开始是想到计算出该位置与前16个位置的16个答案并得出哪一个最小的,之后在进行一次运算让运算结果等于这个最小值的位置输出。 这样的话机会很累。 所以附上自己改良后的代码,其核心部分的内容是: 首先定义一个min1使其很大,之后循环16次,让每一次

scanferror的博客 471

联想开天N70z/N79Z G1d笔记本Win驱动下载

本文介绍了联想开天N70Z/N79Z G1d笔记本在Win11系统下的驱动安装方法。提供了WiFi网卡驱动(RealtekWlan)和显卡驱动(ZX C960 GPU)的详细安装步骤,包括手动更新驱动和卸载流程。驱动安装后成功支持5G WiFi连接并正确识别显卡型号。文中附有系统信息和安装效果截图,同时提供了官方驱动下载地址及备用下载链接。该指南适用于需要为联想开天N70Z/N79Z G1d笔记本安装Win11驱动的用户参考。

信创运维工程师 · 银河麒麟 & 容器实战 | 金融生产环境迁移·等保加固 | 142篇原创·17万+阅读 3872

ZOJ-1067-Color Me Less

Nothing to say,整理好输入,选一个最小的距离就是了//2007-12-30 00:57:25 Accepted 1067 C++ 00:00.00 396K #include#includeint target[16][3];int now[3];double distance(int a[3],int b[3]){ double re; re = (a[0]-b[0])

outer of the space 1141

IMSL CNL 7.0.0 (x86-64)Crack

IMSL CNL 7.0.0 (x86-64)Crack intel的算法库破解文件,这是C++版本的破解文件

Devexpress16.2.6破解工具

Devexpress16.2.6破解工具Devexpress16.2.6破解工具Devexpress16.2.6破解工具Devexpress16.2.6破解工具

ZOJ 1067 Color Me Less

Color Me Less Time Limit: 2 Seconds      Memory Limit: 65536 KB Problem A color reduction is a mapping from a set of discrete colors to a smaller one. The solution to this problem requires th

胖子加油! 509

温度PID控制PLC程序

温度PID稳定控制程序,适用于欧姆龙PLC,对其他PLC也具有很大参考价值

ZOJ 1067 :Color Me Less

简单题目,直接贴代码。 #include struct Color { int r,g,b; }map[16]; int main() { //freopen("1.txt","r",stdin); for(int i=0;i<16;i++) scanf("%d%d%d",&map[i].r,&map[i].g,&map[i].b); Color c; while(scanf(

728

霍尼韦尔SoftMaster使用说明

霍尼韦尔SoftMaster使用说明

ZOJ Problem Set - 1067 Color Me Less

ZOJ Problem Set - 1067 Color Me Less Time Limit: 2 Seconds                                     Memory Limit: 65536 KB                             Problem   A color reduction is a mapp

Jackwuyongxing的专栏 693

ZOJ--1067:Color Me Less

思路: 这题是让 先输入十六组数 然后给后面的每组数 从这十六组数中找通过那个式子值最小的 一组数据 ; 比较简单 不解释 java: import java.util.Scanner; public class Color_Me_Less_1067 { public static void main(String[] args) { Scanner s=new Scanner(S

yf224的博客 482

Python ZOJ1067 Color Me Less

从题目里我们知道,我们需要把这些RGB颜色储存起来,而在后面每一个RGB2都要计算与目标集合里的每一个RGB1的距离进行比较,要经常访问RGB(R, G, B)所以一个较为有效的储存方式显得尤为重要。接下来的输入直到出现"-1 -1 -1" 的结束标志前,都是RGB2(R2, G2, B2)我们在题目中主要访问的是RGB中的变量R、变量G和变量B,所以何不为RGB创建一个类?我们要做的,则是找出每一个RGB2对应的最近的RGB1。两个RGB颜色之间的“距离”公式如图。“-1 -1 -1”是输入的集合标志。

m0_73353724的博客 238

ZOJ Problem Set - 1067||Color Me Less

Color Me Less Time Limit: 2 Seconds      Memory Limit: 65536 KB Problem A color reduction is a mapping from a set of discrete colors to a smaller one. The solution to this problem requires th

飞舞的指尖 567

ZOJ1067-Color Me Less

#include #include struct stdcolor { int R; int G; int B; }; stdcolor col[16]; double distance(stdcolor c, stdcolor co) { double dis; dis = pow(c.R - co.R, 2) + pow(c.G - co.G,

Collider 515

ZOJ Problem Set - 1067 Color Me Less

Color Me Less Time Limit: 2 Seconds      Memory Limit: 65536 KB Problem A color reduction is a mapping from a set of discrete colors to a smaller one. The solution to this problem require

acm_1361677193的专栏 433

zoj 1067 Color Me Less

正确代码: #include #include #include using namespace std; int main() { int tar[16][3]; for(int i=0;i<16;i++) for(int j=0;j<3;j++) cin >> tar[i][j]; int color[100][3]={0}; int m=0,n=0,count=0;

zeron_oo的专栏 691

ZOJ1067Color Me Less

#include using namespace std; #define N 16 int main() { int R[16],G[16],B[16]; int r,g,b; for(int ii=0;ii<N;ii++) //读入目标集合 cin>>R[ii]>>G[ii]>>B[ii]; while(1) { cin>>r>>g>>b; if(r==-1 &&

香小鱼 638

ZOJ1067 Color Me Less

Code highlighting produced by Actipro CodeHighlighter (freeware)http://www.CodeHighlighter.com/-->#include iostream>#include cmath>#include limits>using namespace std;const int

996
上一篇: ZOJ_1051_A New Growth Industry
下一篇: ZOJ_1115_Digital Roots
wankaiming
博客等级 码龄15年 49粉丝 27原创
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

个

红包个数最小为10个

元

红包金额最低5元

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

抵扣说明:

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

余额充值