对于计算机而言,颜色不过是像素点对应的一个24位的数值。现给定一幅分辨率为MxN的画,要求你找出万绿丛中的一点红,即有独一无二颜色的那个像素点,并且该点的颜色与其周围8个相邻像素的颜色差充分大。

输入格式:

输入第一行给出三个正整数,分别是M和N(<= 1000),即图像的分辨率;以及TOL,是所求像素点与相邻点的颜色差阈值,色差超过TOL的点才被考虑。随后N行,每行给出M个像素的颜色值,范围在[0, 224)内。所有同行数字间用空格或TAB分开。

输出格式:

在一行中按照“(x, y): color”的格式输出所求像素点的位置以及颜色值,其中位置x和y分别是该像素在图像矩阵中的列、行编号(从1开始编号)。如果这样的点不唯一,则输出“Not Unique”;如果这样的点不存在,则输出“Not Exist”。

输入样例1:

8 6 200
0 0 0 0 0 0 0 0
65280 65280 65280 16711479 65280 65280 65280 65280
16711479 65280 65280 65280 16711680 65280 65280 65280
65280 65280 65280 65280 65280 65280 165280 165280
65280 65280 16777015 65280 65280 165280 65480 165280
16777215 16777215 16777215 16777215 16777215 16777215 16777215 16777215

输出样例1:

(5, 3): 16711680

输入样例2:

4 5 2
0 0 0 0
0 0 3 0
0 0 0 0
0 5 0 0
0 0 0 0

输出样例2:

Not Unique

输入样例3:

3 3 5
1 2 3
3 4 5
5 6 7

输出样例3:

Not Exist
 package com.hone.basical;

 import java.util.HashMap;
import java.util.Map;
import java.util.Scanner;
/**
* 原题目:https://www.patest.cn/contests/pat-b-practise/1067
* @author Xia
* 题目有三个核心地方:
* (1):该点必须是唯一的,一点绿,也就是说如果不是唯一,则直接跳过。
* (2):怎么样存储才能保证其唯一性呢?用数值作为数组下标的方式?肯定不妥当,因为像素点涉及到2的24次方,如果强行建立一个大的数组,内存肯定得爆炸。
* (3):现在有一个疑惑?
* 二维数组四周的元素到底能不能算?毕竟他没有周围八个元素。
* 如果周围的元素检查,则得建立一个方法避免数组越界的情况。
* 尽管如此,内存还是爆炸了。。
*/ public class basicalLevel1068color {
static int a;
static int b;
static int[][] color = new int[1001][1001];
static int tol; //用一个dir指引四周的八种情况的变化
static int[][] dir ={{-1,-1},{-1,0},{-1,1},{0,-1},{0,1},{1,-1},{1,0},{1,1}};
public static void main(String[] args) {
Scanner in = new Scanner(System.in);
a = in.nextInt();
b = in.nextInt();
tol = in.nextInt();
Map<Integer, Integer> times = new HashMap<>(); //用一个map来存储每一个的出现次数
for (int i = 0; i < b; i++) {
for (int j = 0; j < a; j++) {
color[i][j] = in.nextInt();
if (times.get(color[i][j])!=null) {
int index = times.get(color[i][j]);
times.put(color[i][j], index+1);
}else {
times.put(color[i][j], 1);
}
}
}
int row = -1;
int col = -1;
int num = 0;
for (int i = 0; i < b; i++) {
for (int j = 0; j < a; j++) {
if (times.get(color[i][j]) == 1&&check(i, j)) {
num++;
row = i;
col = j;
}
}
} if (num > 1) {
System.out.println("Not Unique");
}else if (num == 1) {
System.out.println("("+(col+1)+", "+(row+1)+"): "+color[row][col]);
}else if (num == 0) {
System.out.println("Not Exist");
}
} /**
* 检查是否符合要求
* @param x
* @param y
* @return
*/
public static boolean check(int x,int y){
boolean sigle = true;
for (int h = 0; h < 8; h++) {
int xx = x + dir[h][0];
int yy = y + dir[h][1];
if(xx>=0 && xx<b && yy<a && yy>=0 && Math.abs(color[xx][yy]-color[x][y])<=tol) sigle = false;
}
return sigle;
} }
												

最新文章

  1. nyoj-一笔画问题-欧拉图+联通判定
  2. Android之Activity之间跳转
  3. 结对编程之Fault、Error、Failure
  4. CSS3中的calc()
  5. C# - 函数参数的传递
  6. linux date
  7. MongoDB索引(一)
  8. Hive语法
  9. 数据库mysql大全(高级版)
  10. 封装一个 员工类 使用preparedStatement 查询数据 (1)
  11. 第14章 添加JavaScript客户端 - Identity Server 4 中文文档(v1.0.0)
  12. js 字符串的replace() 方法和实现replaceAll() 方法
  13. 总结:Java 集合进阶精讲2-ArrayList
  14. mysql alter add 使用记录
  15. bitbucket 上公钥SSH key如何add key并进行项目运用
  16. [BZOJ4842]Delight for a Cat[费用流]
  17. 传智播客c/c++公开课学习笔记--邮箱账户的破解与邮箱安全防控
  18. python执行系统命令后获取返回值
  19. div固定顶部和底部
  20. CentOS6.5(4)----宿主机无法访问虚拟机中的web服务解决方案

热门文章

  1. eml文件解析实例,简历信息抓取工具
  2. The configuration section &#39;system.serviceModel&#39; cannot be read because it is missing a section decla
  3. PHP 经典算法
  4. Swiper轮播图
  5. C# 按部门拆分excel文件
  6. LeetCode 514----Freedom Trail
  7. Django最佳实践(中文版)
  8. GAN背后的数学原理
  9. 微信小程序开发9-宿主环境(2)
  10. 《你不知道的JavaScript-上卷》笔记