昨天晚上参加了华为OD的机考,记录一下考试流程,顺便做个复盘。
一、华为OD机考流程
- 考试流程
- 邮箱接收考试地址
- 电脑网页登入,确认个人信息
- 开启摄像头,并拍照(考试过程全程开启)
- 开启全屏幕录制
- 手机扫描二维码,进入小程序页面(必须在这个页面停留,手机常亮,直到交卷)
- 开始考试(3到算法题,一共400分,分值分布100、100、150,150及格)
二、灰度图
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21
| 题干: 黑白图像常采用灰度图的方式存储,即图像的每个像素填充一个灰阶值。 256阶灰度图是一个灰阶值取值范围为0-255的灰阶矩阵,0表示全黑、255表示全白,范围内的其他值表示不同的灰度。 比如下面的图像及其对应的灰阶矩阵 10 10 255 34 0 1 255 8 0 3 255 6 0 5 255 4 0 7 255 2 0 9 255 21 1、所有数值以空格分隔 2、前两个数分别表示矩阵的行数和列数 3、从第三个数开始,每两个数一组,每组第一个数是灰阶值,第二个数表示该灰阶值从左到右,从上到下(可理解为将二维数组按行存储在一维矩阵中)的连续像素个数。比如题目所述例子,“255 34”表示有连续34个像素的灰阶值是255。 如此,图像软件在打开此格式灰度图的时候,就可以根据此算法从压缩数据恢复出原始灰度图矩阵。 请从输入的压缩数恢复灰度图原始矩阵,并返回指定像素的灰阶值。
10 10 255 34 0 1 255 8 0 3 255 6 0 5 255 4 0 7 255 2 0 9 255 21 3 4 输入包括两行,第一行是灰度图压缩数据,第二行表示一个像素位置的行号和列号,如:0 0 表示左上角像素。
附加条件: 输入数据表示的灰阶矩阵的指定像素的灰阶值。 1、系统保证输入的压缩数据是合法有效的,不会出现数据越界、数值不合法等无法恢复的场景; 2、系统保证输入的像素坐标是合法的,不会出现不在矩阵中的像素; 3、矩阵的行和列数范围为:(0,100]; 4、灰阶值取值范围:[0, 255];
|
由于长期使用ChatGPT等工具原因,考试不能百度、代码也不能补全,因此很多基础的语法都有些生疏了。科学飞速发展的阶段,我享受科技进步带来的便捷,并逐渐产生依赖。当有一天它不能使用时,亦或是像如今的手机一样,AI时代的到临,人类该何去何从?越说越远了,哈哈哈,上代码吧。下面是我的解题思路及全部代码。(遇事不决、暴力破解)
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135
| import java.util.ArrayList; import java.util.List;
public class one {
public static void main(String[] args) {
String origin = "10 10 56 34 99 1 87 8 99 3 255 6 99 5 255 4 99 7 255 2 99 9 255 21\n1 1";
final String grayValue = getGrayValue(origin); System.out.println(grayValue);
}
private static String getGrayValue(String origin) { String data = origin.split("\n")[0]; String[] split = data.split(" "); String row = split[0]; String column = split[1]; List<String> list = new ArrayList<>(); for (int i = 0; i < split.length; i++) { if (i == 0 || i == 1) { } else { list.add(split[i]); } } System.out.println("row: " + row); System.out.println("column: " + column); System.out.println("list: " + list); List<String> colour = new ArrayList<>(); List<String> location = new ArrayList<>(); boolean flag = true; for (int i = 0; i < list.size(); i++) { if (flag) { colour.add(list.get(i)); flag = false; } else { location.add(list.get(i)); flag = true; } } System.out.println("colour:" + colour); System.out.println("location:" + location);
String input = origin.split("\n")[1]; final String row_value = input.split(" ")[0]; final String column_value = input.split(" ")[1]; System.out.println("row_value: " + row_value); System.out.println("column_value: " + column_value); int target_location = (Integer.parseInt(row_value) - 1) * Integer.parseInt(row) + Integer.parseInt(column_value); System.out.println("target_location:" + target_location);
final int index = getIndex(location, target_location); System.out.println("index:" + index); System.out.println("result:" + colour.get(index)); return colour.get(index); }
private static int getIndex(List<String> location, int target_location) { for (int i = 0; i < location.size(); i++) { int location_sum = 0; for (int i1 = 0; i1 < i+1; i1++) { location_sum += Integer.parseInt(location.get(i1)); } if (target_location <= location_sum) { return i; } } return -1; } }
|
现在我们在借助科技的力量,看看ChatGPT怎么解。
输入题干后,我们的人工智能GPT,15秒就给出了解题思路和答案,接下来让我们一起看一下吧。
1 2 3 4
| 主要任务是从给定的压缩数据中恢复出原始灰度图矩阵,并且能够根据给定的像素位置返回其灰阶值。 1.解析输入数据:首先,我们需要解析输入的压缩数据和像素位置。 2.恢复灰度图矩阵:根据压缩数据,我们可以构建原始的灰度图矩阵。对于每一组压缩数据,我们将对应的灰阶值填充到矩阵中连续的像素位置。 3.返回指定像素的灰阶值:根据给定的像素位置,我们可以直接在恢复的灰度图矩阵中查找对应位置的灰阶值。
|
下面是相应的Java代码实现:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33
| import java.util.Scanner;
public class Main { public static void main(String[] args) { Scanner scanner = new Scanner(System.in); String compressData = scanner.nextLine(); String[] pixelPosition = scanner.nextLine().split(" ");
String[] compressArr = compressData.split(" "); int rows = Integer.parseInt(compressArr[0]); int cols = Integer.parseInt(compressArr[1]);
int[][] matrix = new int[rows][cols]; int index = 2; for (int i = 0; i < rows; i++) { for (int j = 0; j < cols; j++) { int grayValue = Integer.parseInt(compressArr[index]); int pixelCount = Integer.parseInt(compressArr[index + 1]); matrix[i][j] = grayValue; index += 2; } }
int row = Integer.parseInt(pixelPosition[0]); int col = Integer.parseInt(pixelPosition[1]); int grayValue = matrix[row][col]; System.out.println(grayValue); } }
|
很显然,他提供的逻辑是错误的,看来GTP3.5的智商还是不够啊,期待GPT7的到来,今晚听360周总说要在2027年,智商高达140,正常人也就100的智商,爱因斯坦160的智商,这样的超级人工智能,福兮祸兮,三年后一见分晓。