[Offer收割]编程练习赛40 register

Ended

Participants:189

Verdict:Accepted
Score:100 / 100
Submitted:2017-12-17 13:26:09

Lang:G++

Edit
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
#include<iostream>
#include<cstdio>
#include<set>
#define maxn 105
using namespace std;
int a[maxn][maxn];
int main(){
#ifdef WFX
freopen("in.txt","r",stdin);
#endif
    int N,M;
    scanf("%d%d",&N,&M);
    for(int i=0;i<N;++i) {
        for(int j=0;j<M;++j){
            scanf("%d",&a[i][j]);
        }
    }
    
    int ans=0;
    for(int i=1,n=N-1; i<n; ++i){
        for(int j=1,m=M-1; j<m; ++j){
            set<int> s;
            for(int k=-1; k<=1; ++k){
                s.insert(a[i+k][j-1] + a[i+k][j] + a[i+k][j+1] );
                s.insert(a[i-1][j+k] + a[i][j+k] + a[i+1][j+k] );
            } 
            s.insert(a[i-1][j-1] + a[i][j] + a[i+1][j+1]);
            s.insert(a[i+1][j-1] + a[i][j] + a[i-1][j+1]);
            if(s.size() == 1) ++ans;
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX