POJ1046
来源:互联网 发布:遥知不是雪为有暗香来 编辑:程序博客网 时间:2024/05/21 19:42
题目:http://acm.pku.edu.cn/JudgeOnline/problem?id=1046
思路:读懂题目就会做。。。前16行是一个给你判断的集合,后面才是要计算的具体数据,拿下面和上面16行依次计算,输出D最小的RGB就行。
- import java.util.Scanner;
- public class Main {
- int[][] rgb = new int[16][3];
- int r;
- int g;
- int b;
- int map;
- double d;
- double t;
- static final double D = Math.sqrt(255 * 255 * 3);
- public Main() {
- Scanner scan = new Scanner(System.in);
- for (int i = 0; i < 16; i++) {
- for (int j = 0; j < 3; j++) {
- rgb[i][j] = scan.nextInt();
- }
- }
- r = scan.nextInt();
- g = scan.nextInt();
- b = scan.nextInt();
- while (r != -1 && g != -1 && b != -1) {
- d = D;
- for (int i = 0; i < 16; i++) {
- t = Math.sqrt(Math.pow(rgb[i][0] - r, 2)
- + Math.pow(rgb[i][1] - g, 2)
- + Math.pow(rgb[i][2] - b, 2));
- if (t < d) {
- map = i;
- d = t;
- }
- }
- System.out.printf("(%d,%d,%d) maps to (%d,%d,%d)/n", r, g, b,
- rgb[map][0], rgb[map][1], rgb[map][2]);
- r = scan.nextInt();
- g = scan.nextInt();
- b = scan.nextInt();
- }
- }
- public static void main(String[] args) {
- new Main();
- }
- }
- POJ1046
- POJ1046
- poj1046
- poj1046
- poj1046
- poj1046
- POJ1046
- poj1046
- poj1046
- poj1046
- poj1046 枚举
- POJ1046解题报告
- POJ1046解题报告
- poj1046 枚举法
- poj1046 简单题
- 1poj1046(水题)
- poj1046 color me less
- POJ1046;Color me less
- 在Eclipse WTP 2.0上安装GlassFish V2插件
- glassfish性能配置
- getElementByID,getElementsByName,getElementsByTagName的区别
- Tomcat的Socket实现:org.apache.tomcat.util.net(一)
- Java关键字final、static使用总结
- POJ1046
- CoLinux入门教程
- 收藏:JDBC常用连接写法(包括MySQL、Oracle、Sybase、SQLServer、DB2)
- javascript经典代码
- 在二叉树中找出和为某一值的所有路径
- 线索二叉树(threaded binary search tree) C#
- C#教程第6讲方法2(学习笔记)
- 10g中表监控与statistics_level
- 省市关联联动下拉代码