码迷,mamicode.com
首页 > 其他好文 > 详细

poj 1046

时间:2014-08-19 14:37:44      阅读:195      评论:0      收藏:0      [点我收藏+]

标签:poj   数学   

<div class="plm" style="text-align: center; font-size: 12pt; color: rgb(51, 51, 51); clear: both;"><div class="ptt" id="problem_title" style="font-size: 18pt; font-weight: bold; color: blue; padding: 10px;"><span style="color: green;"> </span>Color Me Less</div><span id="crawlSuccess" class="crawlInfo" style="display: inline;"><strong>Time Limit:</strong><span id="timeLimit">1000</span>MS     <strong>Memory Limit:</strong><span id="memoryLimit">10000</span>KB     <strong>64bit IO Format:</strong><span id="_64IOFormat">%I64d & %I64u</span></span><div id="problem_opt" style="font-size: 12px; margin-top: 10px;"><a target=_blank id="submit" class="ui-button ui-widget ui-state-default ui-corner-all ui-button-text-only" role="button" style="font-family: Verdana, Arial, sans-serif; font-size: 1em; border: 1px solid rgb(211, 211, 211); background-image: url(http://i.vjudge.net/vjudge/jquery-ui-1.8.16.custom/css/custom-theme/images/ui-bg_glass_75_e3e4f8_1x400.png); background-color: rgb(227, 228, 248); color: rgb(85, 85, 85); border-top-left-radius: 4px; border-top-right-radius: 4px; border-bottom-left-radius: 4px; border-bottom-right-radius: 4px; display: inline-block; position: relative; padding: 0px; margin-right: 0.1em; cursor: pointer; zoom: 1; overflow: visible; background-position: 50% 50%; background-repeat: repeat no-repeat;"><span class="ui-button-text" style="display: block; line-height: 1.4; padding: 0.4em 1em;">Submit</span></a> <a target=_blank id="problem_status" href="http://i.vjudge.net/vjudge/contest/view.action?cid=54209#status//D/0" class="ui-button ui-widget ui-state-default ui-corner-all ui-button-text-only" role="button" style="font-family: Verdana, Arial, sans-serif; font-size: 1em; border: 1px solid rgb(211, 211, 211); background-image: url(http://i.vjudge.net/vjudge/jquery-ui-1.8.16.custom/css/custom-theme/images/ui-bg_glass_75_e3e4f8_1x400.png); background-color: rgb(227, 228, 248); color: rgb(85, 85, 85); border-top-left-radius: 4px; border-top-right-radius: 4px; border-bottom-left-radius: 4px; border-bottom-right-radius: 4px; display: inline-block; position: relative; padding: 0px; margin-right: 0.1em; cursor: pointer; zoom: 1; overflow: visible; text-decoration: none; background-position: 50% 50%; background-repeat: repeat no-repeat;"><span class="ui-button-text" style="display: block; line-height: 1.4; padding: 0.4em 1em;">Status</span></a></div></div><div style="color: rgb(51, 51, 51); font-family: Verdana, Arial, sans-serif; font-size: 14px; width: 960px; margin: auto;"><div class="hiddable" id="vj_description" style="font-family: 'times new roman'; font-size: 17px;"><p class="pst" style="font-family: Arial, Helvetica, sans-serif; font-size: 18pt; font-weight: bold; color: blue; margin-bottom: 0px;">Description</p><div class="textBG" style="background-color: rgb(234, 235, 255); border-top-left-radius: 10px; border-top-right-radius: 10px; border-bottom-right-radius: 10px; border-bottom-left-radius: 10px; padding: 10px; border-style: dotted; border-width: 2px;"><div class="ptx" lang="en-US" style="font-family: 'Times New Roman', Times, serif; font-size: 12pt;">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 
<center><img src="http://poj.org/images/1046/color.gif" alt="" /></center></div></div></div><div class="hiddable" id="vj_input" style="font-family: 'times new roman'; font-size: 17px;"><p class="pst" style="font-family: Arial, Helvetica, sans-serif; font-size: 18pt; font-weight: bold; color: blue; margin-bottom: 0px;">Input</p><div class="textBG" style="background-color: rgb(234, 235, 255); border-top-left-radius: 10px; border-top-right-radius: 10px; border-bottom-right-radius: 10px; border-bottom-left-radius: 10px; padding: 10px; border-style: dotted; border-width: 2px;"><div class="ptx" lang="en-US" style="font-family: 'Times New Roman', Times, serif; font-size: 12pt;">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.</div></div></div><div class="hiddable" id="vj_output" style="font-family: 'times new roman'; font-size: 17px;"><p class="pst" style="font-family: Arial, Helvetica, sans-serif; font-size: 18pt; font-weight: bold; color: blue; margin-bottom: 0px;">Output</p><div class="textBG" style="background-color: rgb(234, 235, 255); border-top-left-radius: 10px; border-top-right-radius: 10px; border-bottom-right-radius: 10px; border-bottom-left-radius: 10px; padding: 10px; border-style: dotted; border-width: 2px;"><div class="ptx" lang="en-US" style="font-family: 'Times New Roman', Times, serif; font-size: 12pt;">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.</div></div></div><div class="hiddable" id="vj_sampleInput" style="font-family: 'times new roman'; font-size: 17px;"><p class="pst" style="font-family: Arial, Helvetica, sans-serif; font-size: 18pt; font-weight: bold; color: blue; margin-bottom: 0px;">Sample Input</p><div class="textBG" style="background-color: rgb(234, 235, 255); border-top-left-radius: 10px; border-top-right-radius: 10px; border-bottom-right-radius: 10px; border-bottom-left-radius: 10px; padding: 10px; border-style: dotted; border-width: 2px;"><pre class="sio" style="white-space: pre-wrap; word-wrap: break-word; font-family: 'Courier New', Courier, monospace; font-size: 12pt;">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)
题意:

给出16行数字,再输入数据,找到前面16行数字中,与之距离最近的点。
思路:
当然可以用结构体来做,但是合理的运用while(1)能更好地解决问题。
代码如下:
#include<stdio.h>
int main()
{
	int i,j,flag=0;
	int a[16],b[16],c[16];
	for(i=0;i<16;i++)
	{
		scanf("%d%d%d",&a[i],&b[i],&c[i]);
	}
	int d,x,y,z,s;
	while(1)
	{
		scanf("%d%d%d",&x,&y,&z);
		if(x==-1&&y==-1&&z==-1)
		break;
		d=(x-a[0])*(x-a[0])+(y-b[0])*(y-b[0])+(z-c[0])*(z-c[0]);
		for(i=1;i<16;i++)
		{
			s=(x-a[i])*(x-a[i])+(y-b[i])*(y-b[i])+(z-c[i])*(z-c[i]);
			if(d>s)
			d=s,flag=i;
		}
		printf("(%d,%d,%d) maps to (%d,%d,%d)\n",x,y,z,a[flag],b[flag],c[flag]);
	}
	
	return 0;
}

poj 1046,布布扣,bubuko.com

poj 1046

标签:poj   数学   

原文地址:http://blog.csdn.net/ice_alone/article/details/38680225

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!