当前位置:网站首页>Solving for the number of mines

Solving for the number of mines

2022-08-10 01:47:00 -JMY-

题目描述

In order to ensure that important military bases on the border will not be invaded by the enemy,Our army was buried on the way the enemy army must passx颗地雷,known this

The place to go isn * msquare shape,To let our friendly forces know where there are mines,Our military engineers drew one

Mine distribution map.in this distribution,If there are no mines at a certain point,Then the sum of the bits of the number marked by this point will be one

个偶数;Conversely, if the point has a mine,The sum of the bits of the number marked by this point is an odd number.

Please program it out,How many mines have been planted in the area in total.

比如:There is one below5 * 6mine distribution map,The areas in which the mines are buried are marked with a grey background,shared in this area

10颗地雷.

12

35

90

21

1

9

91

3892

8749

342

3421

89

1881

1111

39

4

1

34

9

93

34

12

45

0

67

4

34

19

235

32

输入

第一行有两个整数n和m,Respectively represent the size of the mapn行m列(n和m都是10~100之间的整数)

接下来n行,每行有m个整数,The number of markers representing whether there are mines(These numbers are all marked<=9999的整数)

输出

一个整数,Indicates how many mines have been planted in the area.

样例输入

5 6
12 35 90 21 1 9
91 3892 8749 342 3421 89
1881 1111 39 4 1 34
9 93 34 12 45 0
67 4 34 19 235 32

样例输出

16

参考代码:

#include<bits/stdc++.h>
using namespace std;
int n,m,a[105][105],s;
int f(int x){
    int k=0;
    while(x!=0){
        k+=x%10;
        x/=10;
    }
    return k%2;
}
int main(){
    scanf("%d%d",&n,&m);
    for(int i=0;i<n;i++)
        for(int j=0;j<m;j++){
            scanf("%d",&a[i][j]);
            if(f(a[i][j])==1)
                s++;
        }
    printf("%d",s);
    return 0;
}

原网站

版权声明
本文为[-JMY-]所创,转载请带上原文链接,感谢
https://yzsam.com/2022/222/202208092346036681.html