18: Tumor area, 18 tumor Area

Source: Internet
Author: User

18: Tumor area, 18 tumor Area
18: Tumor Area

  • View
  • Submit
  • Statistics
  • Question
Total time limit:
1000 ms
 
Memory limit:
65536kB
Description

On a square grayscale image, the tumor is a rectangular area, and the pixel of the tumor edge is represented by 0 in the image. Other tumors and vertices outside the tumor are expressed as 255. Now you need to write a program to calculate the number of pixels inside the tumor (excluding vertices on the tumor edge ). It is known that the tumor edge is parallel to the image edge.

Input
There is only one test sample. The first line has an integer n, indicating the side length of the square image. Each row in the next n Rows has n integers. The values are 0 or 255. Integers are separated by a space. It is known that n is not greater than 1000.
Output
Output a row containing an integer, which is the number of pixels in the required tumor.
Sample Input
5255 255 255 255 255255 0 0 0 255255 0 255 0 255255 0 0 0 255255 255 255 255 255
Sample output
1
Prompt
If you use a static array to represent image data, you need to define the array as a global variable.
Source
2005 ~ 2006 Final Examination of Introduction to computing in the Medical Department
 1 #include<iostream> 2 using namespace std; 3 int a[1001][1001]; 4 int now=1; 5 int tot=0; 6 int hang,lie; 7 int l_h; 8 int l_l; 9 int ans=0;10 int main() 11 {12     int n;13     cin>>n;14     for(int i=1;i<=n;i++)15     {16         for(int j=1;j<=n;j++)17         {18             cin>>a[i][j];19         }20     }21     for(int i=1;i<=n;i++)22     {23         for(int j=1;j<=n;j++)24         {25             if(a[i-1][j]==0&&a[i-1][j-1]==0&&a[i][j-1]==0&&i!=1&&j!=1)26             {27                 hang=i;28                 lie=j;29             }30         }31     }32     for(int i=hang;i<=9999;i++)33     {34         for(int j=lie;j<=9999;j++)35         {36             if(a[i][j]!=0)37             {38                 l_l++;39             }40             else break;41         }42         break;43     }44     for(int i=hang;i<=9999;i++)45     {46         if(a[i][lie]!=0)47         {48             l_h++;49         }50         else break;51     }52     cout<<l_h*l_l;53     return 0;54 }

 

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.