2713:肿瘤面积

2713:肿瘤面积

总时间限制: 
1000ms 
内存限制: 
65536kB
描述

在一个正方形的灰度图片上,肿瘤是一块矩形的区域,肿瘤的边缘所在的像素点在图片中用0表示。其它肿瘤内和肿瘤外的点都用255表示。现在要求你编写一个程序,计算肿瘤内部的像素点的个数(不包括肿瘤边缘上的点)。已知肿瘤的边缘平行于图像的边缘。

输入
只有一个测试样例。第一行有一个整数n,表示正方形图像的边长。其后n行每行有n个整数,取值为0或255。整数之间用一个空格隔开。已知n不大于1000。
输出
输出一行,该行包含一个整数,为要求的肿瘤内的像素点的个数。
样例输入
5
255 255 255 255 255
255 0 0 0 255
255 0 255 0 255
255 0 0 0 255
255 255 255 255 255
样例输出
1
提示

如果使用静态数组来表示图片数据,需要将该数组定义成全局变量。


#include <stdio.h>
#include <iostream>
#include <stack>
#include <string.h>
#include <queue>
#include <cmath>
#include <vector>
#include <algorithm>
#include <map>
#include <set>
#include <string>
using namespace std;
typedef long long LL;
int a[1001][1001];
int main() {
    //freopen("in.txt", "r", stdin);
    //freopen("out.txt","w",stdout);
    int n;
    cin >> n;
    int count = 0;
    for(int i = 0; i < n; i++){
        int x = 0;
        int y = 0;
        for(int j = 0; j < n;j ++){
            int temp;
            cin >> temp;
            if(temp == 0){  //扫描每一行中的0元素
                x++;
            }else if(temp == 255 && x > 0 && x < 2){ //扫描每一行 中 位于0元素之间的255
                y++;
            }
        }
        count += y; //最后结果 +y
    }
    cout << count << endl;
    return 0;
}







评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值