Mainly solves the three problems 1. The input of Image Storage adopts RLE encoding, and the storage adopts a similar method, but the point transformation is required. For example, if the input value is 715 4100 1525 2175 225 5175 50 0, to get 7 15 4 100 19 25 21 175 25 28 175 30 25 35 is to change the run length to the index demarcation value. The advantage of doing so is that you need to know the value of the nth pixel and directly compare it with the index demarcation value, which simplifies the search process. 2. The calculation of each pixel edge value is subject to the requirements of the question. Each pixel edge value is the maximum difference between the pixel and the eight-neighbor. This processing method can be used: Set the flag bit for the eight fields. The Initialization is true, indicating that the neighbor exists. Then, the pixel index is used to determine whether the flag is on the boundary of the image, for example, the pixels in the upper left corner do not exist in the fields on the left and the upper left. The adjacent flag is updated based on different situations. Finally, we only consider the field where the flag bit is true and calculate the difference between its value and the current pixel value to determine the edge value. 3. The speed-up technique will definitely time out when processing by pixel. Here there are at least two speed-up techniques. First, if the pixels of multiple rows are the same, a series of edges with 0 values are displayed. Second, if the pixels of multiple columns are the same, a series of edges are displayed. The following is an example of two cases: 2 5 5000000 250 5000000 5000000 0 0 5000000 250 5000000 0 0 0 solution Code # include <stdio. h> # include <stdlib. h> // struct BLOCK {short value; int position ;}; const int N = 1005; // CRLEImage // class for run length encoded image class CRLEImage {private: BLOCK m_data [N]; int m_count; int m_width; public: // constructor CRLEImage (): m_count (0), m_width (0) {m_data [0]. positio N = 0; m_data [0]. value =-1;} // Scan bool Scan () {int width, value, run_length; scanf ("% d", & width); if (width = 0) {printf ("0 \ n"); return false;} m_width = width; int I = 1, index = 0; while (true) {scanf ("% d", & value, & run_length); if (value = 0 & run_length = 0) break; index + = run_length; set_block (I, (short) value, index); ++ I ;}m_count = I-1; return true;} // Process void Proce Ss () {printf ("% d \ n", m_width); short last_edge = calculate_edge (1, 1), edge; int last_idx = 1, idx = 2; for (int I = 1; I <= m_count; ++ I) {while (idx <= m_data [I]. position) {edge = calculate_edge (idx, I); // if edge value change if (edge! = Last_edge) {printf ("% d \ n", (int) last_edge, (idx-last_idx); last_idx = idx; last_edge = edge ;} // same pixels in consecutive rows if (last_edge = 0 & idx-m_data [I-1]. position> m_width + 1 & m_data [I]. position-idx> m_width) idx = m_data [I]. position-m_width; else ++ idx; // same pixels in consecutive columns if (idx % m_width> 2) {int same_length = m_width-1; int idx_arr [3] = {idx- M_width-2, idx-2, idx + m_width-2}; for (int j = 0; j <3; ++ j) {int location, temp; search_pixel (idx_arr [j], I, (idx_arr [j] <idx), location); if (location> 0) {temp = m_data [location]. position-idx_arr [j]; if (temp <same_length) same_length = temp; }}if (same_length> 2) idx ++ = (same_length-2 );}}} printf ("% d \ n", (int) edge, (idx-last_idx); printf ("0 0 \ n");} private: // set block void Set_block (int index, short value, int position) {m_data [index]. value = value; m_data [index]. position = position;} // search pixel short search_pixel (int idx, int block, bool bBackward, int & location) {if (idx <1 | idx> m_data [m_count]. position) {location =-1; return 0;} int I = block; if (bBackward) {for (I = block-1; I> = 0; -- I) if (idx> m_data [I]. position) {location = I + 1; return m_data [I + 1]. value ;}} else {for (I = block; I <= m_count; ++ I) if (idx <= m_data [I]. position) {location = I; return m_data [I]. value ;}}// calculate edge short calculate_edge (int idx, int block) {bool flag [8]; // does neighbor exist for (int I = 0; I <8; ++ I) flag [I] = true; // top if (idx-1)/m_width = 0) flag [0] = flag [1] = flag [2] = false; // bottom if (idx + m_width> m_data [m_count]. position) Flag [5] = flag [6] = flag [7] = false; // left (especially when width is 1) if (m_width = 1 | idx % m_width = 1) flag [0] = flag [3] = flag [5] = false; // right if (idx % m_width = 0) flag [2] = flag [4] = flag [7] = false; // valid neighbor short base = m_data [block]. value; short edge = 0; int nidx; // index of neighbor short for (int I = 0; I <8; ++ I) if (flag [I]) {switch (I) {case 0: case 1: case 2: nidx = idx-m_width + I-1; break; case 3: nidx = idx-1; break; case 4: nidx = idx + 1; break; default: nidx = idx + m_width + I-6;} short neighbor; int location; neighbor = search_pixel (nidx, block, (nidx <idx), location ); short temp = (neighbor> base )? (Neighbor-base): (base-neighbor); if (temp> edge) edge = temp;} return edge ;}; // entry point int main () {CRLEImage image; while (image. scan () image. process (); return 0 ;}