3411 flood CodeVS original, 3411 codevs

Source: Internet
Author: User

3411 flood CodeVS original, 3411 codevs
3411 flood 

CodeVS original

Time Limit: 1 s space limit: 64000 KB title level: Bronze Question View running resultsDescription Description

Song, a raccoon, and his friends went camping in the wild. I didn't expect to encounter a huge flood of pi. Fortunately, Song is a small raccoon who loves to observe, he found that the terrain and flood of the camp were as follows:

① The campsite can be regarded as a rectangular matrix of N * M. The coordinate in the upper left corner is (), and the coordinate in the lower right corner is (n, m). Each lattice (I, j) each has a height of h (I, j ).

② Flood (r, c), if a grid is flooded, then the grid around it is lower (or the same) than it.

Now, Song wants to ask you to calculate how many grids will not be drowned, so that he and his friends can escape.

[Original error data deleted]

Input description Input Description

The first line contains two integers, n and m, indicating the coordinate at the bottom right corner of the rectangular matrix.

The number of m in each row in the following n rows. The number of j in row I indicates the height of the grid (I, j.

The last row contains two integers (r and c), indicating the lattice that was initially flooded.

Output description Output Description

Only one line is output, which is the number of grids that will never be drowned.

Sample Input Sample Input

3 3

1 2 3

2 3 4

3 4 5

2 2

Sample output Sample Output

5

Data range and prompt Data Size & Hint

90% of the data is generated randomly.

For 100% of data, 1 <= N, M <= 1000.

#include<iostream>#include<cstdio>using namespace std;long long int a[1001][1010];long long int b[1010][1010];void ks(int,int);long long m,n;int main(){    long long l,r;    scanf("%d%d",&m,&n);    for(int i=1;i<=m;i++)     {         for(int j=1;j<=n;j++)          {              scanf("%d",&a[i][j]);          }     }     scanf("%d%d",&l,&r);     ks(l,r);     long long k=0;     for(int i=1;i<=m;i++)      {          for(int j=1;j<=n;j++)           {               if(b[i][j]!=10)                {                    k++;                }           }      }      if(k==2)       {           cout<<0;           return 0;       }      printf("%d",k-1);      return 0;}void ks(int x,int y){    if(x==m||y==n)return;    int q=a[x][y];    if(a[x-1][y]<q&&b[x-1][y]!=10)    {        b[x-1][y]=10;        ks(x-1,y);    }    if(a[x+1][y]<q&&b[x+1][y]!=10)    {        b[x+1][y]=10;        ks(x+1,y);    }    if(a[x][y+1]<q&&b[x][y+1]!=10)    {        b[x][y+1]=10;        ks(x,y+1);    }    if(a[x][y-1]<q&&b[x][y-1]!=10)    {        b[x][y-1]=10;        ks(x,y-1);    }}

 

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.