给出两幅相同大小的黑白图像(用0-1矩阵)表示,求它们的相似度。
说明:若两幅图像在相同位置上的像素点颜色相同,则称它们在该位置具有相同的像素点。两幅图像的相似度定义为相同像素点数占总像素点数的百分比。
3 3 1 0 1 0 0 1 1 1 0 1 1 0 0 0 1 0 0 1
44.44
1 #include<iostream> 2 #include<cstdio> 3 using namespace std; 4 char a[1001][1001]; 5 char b[1001][1001]; 6 double tot; 7 int main() 8 { 9 double n,m; 10 cin>>n>>m; 11 for(int i=1;i<=n;i++) 12 { 13 for(int j=1;j<=m;j++) 14 { 15 cin>>a[i][j]; 16 } 17 } 18 for(int i=1;i<=n;i++) 19 { 20 for(int j=1;j<=m;j++) 21 { 22 cin>>b[i][j]; 23 if(a[i][j]==b[i][j]) 24 tot++; 25 } 26 } 27 double ans=tot/(n*m); 28 printf("%.2lf",ans*100); 29 return 0; 30 }
原文:http://www.cnblogs.com/zwfymqz/p/6492026.html