1 条题解

  • 0
    @ 2024-1-21 14:50:54
    #include<bits/stdc++.h>
    using namespace std;
    typedef pair<int,int> PII;
    #define x first
    #define y second
    const int N=1010;
    bool st[N][N];
    int dx[]={0,1,0,-1,1,1,-1,-1};
    int dy[]={1,0,-1,0,1,-1,1,-1};
    int g[N][N];
    int main()
    {
    	int n;
    	cin>>n;
    	for(int i=1;i<=n;i++)
    	{
    		for(int j=1;j<=n;j++)
    		{
    			cin>>g[i][j];
    		}
    	}
    	int a=0,b=0;
    	for(int i=1;i<=n;i++)
    	{
    		for(int j=1;j<=n;j++)
    		{
    			if(!st[i][j])
    			{
    				queue<PII> q;
    				q.push({i,j});
    				st[i][j]=1;
    				int h=0,l=0;
    				while(q.size())
    				{
    					PII t=q.front();
    					q.pop();
    					for(int k=0;k<8;k++)
    					{
    						int tx=t.x+dx[k],ty=t.y+dy[k];
    						if(tx<=0||tx>n||ty<=0||ty>n) continue;
    						if(g[tx][ty]!=g[t.x][t.y])
    						{
    							if(g[t.x][t.y]<g[tx][ty]) l=1;
    							else h=1;
    						}
    						else if(!st[tx][ty])
    						{
    							st[tx][ty]=1;
    							q.push({tx,ty});
    						}
    					}
    				}
    				if(!h) b++;
    				if(!l) a++;
    			}
    		}
    	}
    	cout<<a<<" "<<b;
        return 0;
    }
    
    • 1

    信息

    ID
    626
    时间
    1000ms
    内存
    256MiB
    难度
    10
    标签
    递交数
    5
    已通过
    2
    上传者