The simplest practice of area problems and the practice of area Problems
1. Calculate the area of the following figure enclosed. The area calculation method is to count the number of horizontal and vertical line intersections in the closed curve enclosed. As shown in, in the two-dimensional array of 10*10, "*" contains 15 points, so the area is 15.[Example input]Area. in0 0 0 0 0 0 0 0 0 0 0 0 1 1 1 0 0 00 0 0 0 1 0 0 1 0 0 0 0 0 0 0 1 0 0 0 1 00 0 0 0 0 0 0 1 0 1 00 1 0 1 0 1 0 0 1 00 1 0 1 1 0 1 1 1 1 1 00 0 0 0 0 1 0 0 0 0 0 1 1 1 1 1 1 1 1 0 00 0 0 0 0 0 0 0 0 0[Sample output]Area. out15
1 #include<iostream> 2 using namespace std; 3 int xx[5]={-1,+1,0,0}; 4 int yy[5]={0,0,-1,+1}; 5 int a[101][101]; 6 void dfs(int i,int j) 7 { 8 a[i][j]=1; 9 for(int k=0;k<4;k++)10 {11 int x=i+xx[k];12 int y=j+yy[k];13 if(x>=1&&x<=10&&y>=1&&y<=10&&a[x][y]==0)14 {15 16 dfs(x,y);17 }18 }19 }20 int main()21 {22 for(int i=1;i<=10;i++)23 {24 for(int j=1;j<=10;j++)25 {26 cin>>a[i][j];27 }28 }29 for(int i=1;i<=10;i++)30 {31 if(a[1][i]==0)32 {33 dfs(1,i);34 }35 if(a[i][1]==0)36 {37 dfs(i,1);38 }39 if(a[10][i]==0)40 {41 dfs(10,i);42 }43 if(a[i][10]==0)44 {45 dfs(i,10);46 }47 }48 int tot=0;49 for(int i=1;i<=10;i++)50 {51 for(int j=1;j<=10;j++)52 {53 if(a[i][j]==0)54 tot++;55 }56 }57 cout<<tot;58 return 0;59 }