首页 > 其他分享 >ABC 264 C - Matrix Reducing(思维)

ABC 264 C - Matrix Reducing(思维)

时间:2022-08-14 10:12:34浏览次数:80  
标签:Reducing Matrix int Sample ABC Input Output include

https://atcoder.jp/contests/abc264/tasks/abc264_c

题目大意:

给定n*m的a矩阵,x*y的b矩阵

问能不能删除若干行和列使a变成b?
Sample Input 1 
4 5
1 2 3 4 5
6 7 8 9 10
11 12 13 14 15
16 17 18 19 20
2 3
6 8 9
16 18 19
Sample Output 1 
Yes

Sample Input 2 
3 3
1 1 1
1 1 1
1 1 1
1 1
2
Sample Output 2 
No

这个题目为什么check部分改成从行开始会寄(wa 17)?我不李姐
但是从列开始一列一列的计算就不会

#include<iostream>
#include<cstdio>
#include<cmath>
#include<string>
#include<cstring>
#include<cstdlib>
#include<map>
#include<set>
#include<stack>
#include<queue>
#include<algorithm>
using namespace std;
const int N=200200,M=2002;
int a[M][M],b[M][M];
int n,m,x,y;
bool check(int xx,int yy)
{
    int l=1,r=1;
    for(int j=yy;j<=m;j++)
    {
        l=1;
        for(int i=xx;i<=n;i++)
        {
            if(a[i][j]==b[l][r])
            {
                l++;
            }
            if(l==x+1)
            {
                r++;
                break;
            }
        }
        if(r==y+1) break;
    }
    if(r!=y+1) return false;
    return true;
}
int main()
{
    cin.tie(0); cout.tie(0); ios::sync_with_stdio(false);
    cin>>n>>m;
    for(int i=1;i<=n;i++)
        for(int j=1;j<=m;j++)
        cin>>a[i][j];
    cin>>x>>y;
    for(int i=1;i<=x;i++)
        for(int j=1;j<=y;j++)
        cin>>b[i][j];
    bool flag=false;
    for(int i=1;i<=n;i++)
    {
        for(int j=1;j<=m;j++)
        {
            if(a[i][j]==b[1][1])
            {
                if(check(i,j)==true)
                {
                    flag=true;
                    break;
                }
            }
        }
        if(flag==true) break;
    }
    if(flag==true) cout<<"Yes"<<endl;
    else cout<<"No"<<endl;
    return 0;
}

标签:Reducing,Matrix,int,Sample,ABC,Input,Output,include
From: https://www.cnblogs.com/Vivian-0918/p/16584865.html

相关文章

  • ABC EF 板刷笔记
    菜鸡的刷题记录owo!偶尔也会更一些高质量D题。ABC264E比较秒的一道题。首先将操作反向处理,将摧毁变为修建,跑dsu维护答案即可。总之就是先检查在不在一个连通块,然后发......