又wrong了,题目给的测试数据正确,自己觉得思路也正确,就是不知道错哪了,求指点!
OpenCV
Time Limit: 1000MS Memory Limit: 65535KB
Submissions: 444 Accepted: 95
DescriptionOpenCV (Open Source Computer Vision) is a library of programming functions for real time computer vision. OpenCV is released under a BSD license, it is free for both academic and commercial use. Example applications of the OpenCV library are Human-Computer Interaction (HCI); Object Identification, Segmentation and Recognition; Face Recognition; Gesture Recognition; Camera and Motion Tracking, Ego Motion, Motion Understanding; Structure From Motion (SFM); Stereo and Multi-Camera Calibration and Depth Computation; Mobile Robotics.
Recently ,Phillip has learnt about how to use OpenCV to solve some image problems. Doctor Jiang wants him find the moving items from the given video files. Since using OpenCV can easily deal with such problems, Phillip wants to use his own code to make it out. As we kwon images are saved as a lot of pixels in the computer.
The algorithm that Phillip use is below:
First, we find the different pixels between current image and the previous one image(in this problem we only care the different pixels) .
Second, we record the maximum different number .
InputThe first line are two integers r (row)and c(column) which describe the size of one image. (1 < r, c < 200 );
The second Line is n which is the total number of images (1 < n < 100)
Then n*r lines follow, each line contain exactly c numbers which are pixels of the image in the range of 0 to 255.
OutputOne line with the maximum differenct number you have found.
Sample Input
4 4
3
255 0 0 255
223 221 220 190
10 11 12 13
0 0 0 0
255 1 1 255
245 221 220 100
11 11 0 13
1 1 1 1
255 0 0 255
245 221 220 100
11 11 0 13
1 1 1 1
Sample Output
10
Hint
我的代码
#include<stdio.h>
#include<string.h>
int main()
{
int row,column,n,i,k1,k2,a[256],m,t=0,count;
while(scanf("%d%d",&row,&column)!=EOF)
{
scanf("%d",&n);
for(i=0;i<n;i++)
{
memset(a,0,256*sizeof(int));
count=0;
for(k1=0;k1<row*column;k1++)
{
scanf("%d",&m);
a[m]++;
}
for(k2=0;k2<256;k2++)
{
if(a[k2]>0)
{
count++;
}
}
if(count>=t)
{
t=count;
}
}
printf("%d\n",t);
}
return 0;
}
[解决办法]
#include <iostream>
#include<stdio.h>
#include<string.h>
using namespace std;
int main()
{
int row,column,n,temp;
int max = 0;
int all_max = 0;
scanf("%d %d",&row,&column);
int total = row * column;
int* matrix = new int(total);
memset(matrix,0,total);
scanf("%d",&n);
int i = 0;
// read the first img
for( ; i < 1; i++)
{
for(int j = 0; j < total; j++)
{
scanf("%d",matrix + j);
}
}
// caculate the max
for( ; i < n; i++)
{
max = 0;
for(int j = 0; j < total; j++)
{
scanf("%d",&temp);
if( temp != *(matrix + j))
{
max++;
*(matrix + j) = temp;
}
}
if(max > all_max)
{
all_max = max;
}
}
printf("%d",all_max);
return 0;
}
between current image and the previous one image”
是pixel不是color
半夜我真是闲得。。