编程介的小学生 2019-04-16 17:40 采纳率: 20.5%
浏览 190

方块染色算法的计算机的求解过程,怎么利用C程序语言的设计的技术来编写代码的

Problem Description
We divide the HZNU Campus into N*M grids. As you can see from the picture below, the green grids represent the buidings. Given the size of the HZNU Campus, and the color of each grid, you should count how many green grids in the N*M grids.

Input
Standard input will contain multiple test cases. The first line of the input is a single integer T which is the number of test cases. T test cases follow.
The first line of each test case contains two integers n and m(1<=n,m<=100), the size of the campus. Then follow n lines, each line containing m integers. The j-th integer in the i-th line is the color of that grid, 0 stands for white color, while 1 stands for green.

Output
Results should be directed to standard output. For each case, output an integers T, the total green grids in the N*M size campus.

Sample Input
2
2 2
1 1
0 0
3 3
1 0 1
0 0 1
1 1 0

Sample Output
2
5

  • 写回答

1条回答 默认 最新

  • 格格家的格格巫 2019-11-20 12:55
    关注
    #include <stdio.h>
    #include <stdlib.h>
    
    int main()
    {
        int T;
        scanf("%d",&T);
        int n,m;
        int i;
        int j,k;
        int sum;
        int *p;
        p = (int*)malloc(sizeof(int));
        for(i = 0;i<T;i++)
        {
            sum = 0;
            scanf("%d %d",&n,&m);
            for(j = 0;j<n;j++)
            {
                for(k = 0;k<m;k++)
                {
                    scanf("%d",p);
                    if(*p==1)
                    {
                        sum++;
                    }
                    p++;
                }
            }
            printf("%d\n",sum);
        }
        return 0;
    }
    
    
    评论

报告相同问题?

悬赏问题

  • ¥15 delta降尺度计算的一些细节,有偿
  • ¥15 Arduino红外遥控代码有问题
  • ¥15 数值计算离散正交多项式
  • ¥30 数值计算均差系数编程
  • ¥15 redis-full-check比较 两个集群的数据出错
  • ¥15 Matlab编程问题
  • ¥15 训练的多模态特征融合模型准确度很低怎么办
  • ¥15 kylin启动报错log4j类冲突
  • ¥15 超声波模块测距控制点灯,灯的闪烁很不稳定,经过调试发现测的距离偏大
  • ¥15 import arcpy出现importing _arcgisscripting 找不到相关程序