PAT (Basic Level) Practise (中文) 1068. 万绿丛中一点红(20)
2017-09-15 17:15
363 查看
1068. 万绿丛中一点红(20)
时间限制500 ms
内存限制
65536 kB
代码长度限制
8000 B
判题程序
Standard
作者
CHEN, Yue
对于计算机而言,颜色不过是像素点对应的一个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
//部分正确 1分
//不知道为啥,找到那个点了,但坐标一直不合适,点的大小合适
import java.util.Scanner;
public class num1068 {
public static void main(String[] args) {
Scanner input=new Scanner(System.in);
int m=input.nextInt();
int n=input.nextInt();
int tol=input.nextInt();
int arr[][]=new int[m]
;
for (int i = 0; i < m; i++) {
for (int j = 0; j < n; j++) {
arr[i][j]=input.nextInt();
}
}
int cnt=0;
Point p = new
b452
Point();
for (int i = 1; i < m-1; i++) {
for (int j = 1; j < n-1; j++) {
if (arr[i][j]-arr[i-1][j+1]>tol&&
arr[i][j]-arr[i][j+1]>tol&&
arr[i][j]-arr[i+1][j+1]>tol&&
arr[i][j]-arr[i+1][j]>tol&&
arr[i][j]-arr[i+1][j-1]>tol&&
arr[i][j]-arr[i][j-1]>tol&&
arr[i][j]-arr[i-1][j-1]>tol&&
arr[i][j]-arr[i-1][j]>tol
) {
if (cnt==0) {
p.x=i+1;
p.y=j+1;
p.color=arr[i][j];
cnt++;
}else {
System.out.println("Not Unique");
return;
}
}
}
}
System.out.println(cnt==0?"Not Exist":"("+p.x+", "+p.y+"): "+p.color);
}
}
class Point{
int x;
int y;
int color;
@Override
public String toString() {
//return "("+x+", "+y+"): " + color;
return "("+x+", "+y+"): "+color;
}
}
/*
*自己java这个写的就瞎猫撞死耗子一分
*参考 别人家c++代码
#include <vector>
#include <map>
using namespace std;
int m, n, tol;
vector<vector<int>> v;
int dir[8][2] = {{-1, -1}, {-1, 0}, {-1, 1}, {0, 1}, {1, 1}, {1, 0}, {1, -1}, {0, -1}};
bool judge(int i, int j) {
for (int k = 0; k < 8; k++) {
int tx = i + dir[k][0];
int ty = j + dir[k][1];
if (tx >= 0 && tx < n && ty >= 0 && ty < m && v[i][j] - v[tx][ty] >= 0 - tol && v[i][j] - v[tx][ty] <= tol) return false;
}
return true;
}
int main() {
int cnt = 0, x = 0, y = 0;
scanf("%d%d%d", &m, &n, &tol);
v.resize(n, vector<int>(m));
map<int, int> mapp;
for (int i = 0; i < n; i++) {
for (int j = 0; j < m; j++) {
scanf("%d", &v[i][j]);
mapp[v[i][j]]++;
}
}
for (int i = 0; i < n; i++) {
for (int j = 0; j < m; j++) {
if (mapp[v[i][j]] == 1 && judge(i, j) == true) {
cnt++;
x = i + 1;
y = j + 1;
}
}
}
if (cnt == 1)
printf("(%d, %d): %d", y, x, v[x-1][y-1]);
else if (cnt == 0)
printf("Not Exist");
else
printf("Not Unique");
return 0;
}
*/
相关文章推荐
- PAT (Basic Level) Practise (中文)1068. 万绿丛中一点红(20)
- PAT (Basic Level) Practise (中文)1009. 说反话 (20)
- PAT (Basic Level) Practise (中文)1019. 数字黑洞 (20)
- PAT (Basic Level) Practise (中文)1029. 旧键盘(20)
- PAT (Basic Level) Practise (中文)-1037. 在霍格沃茨找零钱(20)
- PAT (Basic Level) Practise (中文)- 1007. 素数对猜想 (20)
- PAT (Basic Level) Practise (中文)1003. 我要通过!(20)
- PAT (Basic Level) Practise (中文)1014. 福尔摩斯的约会 (20)
- PAT (Basic Level) Practise (中文)1008. 数组元素循环右移问题 (20)
- PAT (Basic Level) Practise (中文)1004. 成绩排名 (20)
- PAT (Basic Level) Practise (中文)1074. 宇宙无敌加法器(20)
- PAT (Basic Level) Practise (中文) 1067. 试密码(20)
- PAT (Basic Level) Practise (中文)1037. 在霍格沃茨找零钱(20)
- PAT (Basic Level) Practise (中文)1002. 写出这个数 (20)
- PAT (Basic Level) Practise (中文)1012. 数字分类 (20)
- PAT (Basic Level) Practise (中文)-1029. 旧键盘(20)
- PAT (Basic Level) Practise (中文)1004. 成绩排名 (20)
- PAT (Basic Level) Practise (中文)1009. 说反话 (20)
- PAT (Basic Level) Practise (中文)1028. 人口普查(20)
- PAT (Basic Level) Practise (中文)1069. 微博转发抽奖(20)