06: image similarity

Total time limit: 1000ms memory limit: 65536kB
description
given two black and white image of the same size (0-1 matrix) that find their similarity.

Note: If the two color pixels in the same image on the same position, they are said to have the same pixel at the position. Define the similarity of two images is the percentage of the total number of pixels of the same number of pixels.

Input
The first line contains two integers m and n, the number of rows and columns of the image, separated by a single space. 1 <= m <= 100, 1 <= n <= 100.
After the m lines of n integers 0 or 1, it represents the color of each pixel of a point on a monochrome image. Separated by a single space between two adjacent numbers.
After the m lines of n integers 0 or 1, it represents the color of each pixel of the monochrome image on the second web. Separated by a single space between two adjacent numbers.
Output
a real number representing the degree of similarity (given in percent), accurate to two decimal places.
Sample input
. 3. 3
. 1. 1 0
0 0. 1
. 1. 1 0
. 1. 1 0
0 0. 1
0 0. 1
Sample Output
44.44

#include<iostream>
using namespace std;
int main(){
	int m,n;
	scanf("%d %d",&m,&n);
	
	int a[m+5][n+5];
	int b[m+5][n+5];
	//输入第一个图的像素位置 
	for(int i=1;i<=m;i++)
	for(int j=1;j<=n;j++){
		scanf("%d",&a[i][j]);
	}
	//输入第二个图的像素位置 
	for(int i=1;i<=m;i++)
	for(int j=1;j<=n;j++){
		scanf("%d",&b[i][j]);
	}
	
	//表示像素点相同的个数 
	int num=0;
	//全部的像素点个数 
	int totalNum=m*n;
	
	
	for(int i=1;i<=m;i++)
	for(int j=1;j<=n;j++){
		if(a[i][j]==b[i][j])
		num++;
	}
	//保留两位小数输出
	printf("%.2f",100.00*num/totalNum);
	
	
	return 0;
}
Published 36 original articles · won praise 0 · Views 353

Guess you like

Origin blog.csdn.net/weixin_44437496/article/details/104005589