#include <iostream> #include <iomanip> using namespace std; int main() { int n, m; // 读取矩阵尺寸 if (!(cin >> n >> m)) { cerr << "输入错误:无法读取矩阵尺寸" << endl; return 1; } // 检查尺寸范围 if (n < 1 || n > 100 || m < 1 || m > 100) { cerr << "输入错误:矩阵尺寸超出范围" << endl; return 1; } // 动态分配并读取第一幅图像 int** image1 = new int*[n]; for (int i = 0; i < n; ++i) { image1[i] = new int[m]; for (int j = 0; j < m; ++j) { if (!(cin >> image1[i][j])) { cerr << "输入错误:无法读取图像数据" << endl; return 1; } // 检查像素值范围 if (image1[i][j] != 0 && image1[i][j] != 1) { cerr << "输入错误:像素值必须为0或1" << endl; return 1; } } } // 读取并比较第二幅图像 int same_count = 0; for (int i = 0; i < n; ++i) { for (int j = 0; j < m; ++j) { int pixel2; if (!(cin >> pixel2)) { cerr << "输入错误:无法读取第二幅图像数据" << endl; return 1; } if (image1[i][j] == pixel2) { same_count++; } } } // 释放内存 for (int i = 0; i < n; ++i) { delete[] image1[i]; } delete[] image1; // 计算相似度 double similarity = (double)same_count / (n * m) * 100.0; // 输出结果,保留两位小数 cout << fixed << setprecision(2) << similarity << endl; return 0; } /************************************************************** Problem: 1998 User: fuyijun Language: C++ Result: Wrong Answer ****************************************************************/