bnu 4351 美女来找茬(水水)

http://www.bnuoj.com/bnuoj/problem_show.php?pid=4351

【题意】:用最小的矩形框,框住像素点差超过5的点。

【题解】:求坐标x,y最大最小值

【code】:

 1 #include <iostream>
 2 #include <stdio.h>
 3 #include <string.h>
 4 #include <algorithm>
 5 
 6 using namespace std;
 7 
 8 int map[220][220];
 9 
10 int abs(int x)
11 {
12     return x<0?-x:x;
13 }
14 
15 int main()
16 {
17     int n,m;
18     scanf("%d%d",&n,&m);
19     int i,j;
20     for(i=0;i<n;i++)
21     {
22         for(j=0;j<m;j++)
23         {
24             scanf("%d",&map[i][j]);
25         }
26     }
27     int x;
28     int x1=1111,x2=-1,y1=1111,y2=-1;
29     int exist=0;
30     for(i=0;i<n;i++)
31     {
32         for(j=0;j<m;j++)
33         {
34             scanf("%d",&x);
35             if(abs(map[i][j]-x)>5)
36             {
37                 exist=1;
38                 if(x1>i)    x1=i;
39                 if(x2<i)    x2=i;
40                 if(y1>j)    y1=j;
41                 if(y2<j)    y2=j;
42             }
43         }
44     }
45     if(exist)
46     {
47         printf("%d %d %d %d
",x1+1,y1+1,x2+1,y2+1);
48     }
49     else
50     {
51         puts("-1");
52     }
53     return 0;
54 }
原文地址:https://www.cnblogs.com/crazyapple/p/3327099.html