HDU 3531 Match(树状数组)
来源:互联网 发布:淘宝被差评有什么影响 编辑:程序博客网 时间:2024/04/30 14:43
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=3531
输入两个0-1矩阵,判断后一个是不是前一个的子矩阵
开始暴力判断,结果超时
后来用树状数组维护枚举区间1的个数,在1的个数相等的情况下来判断是否相等!
#include <string.h>#include <stdio.h>#include <algorithm>#include <iostream>using namespace std;const int maxn = 1005;int first[maxn][maxn],second[maxn][maxn];int tree[maxn][maxn];int n,m;int lowbit(int x){ return (-x)&x;}int update(int i,int j){ int now; while(i<=n){ now=j; while(now<=n){ tree[i][now]++; now+=lowbit(now); } i+=lowbit(i); } return 0;}int sum(int i,int j){ int ans=0,now; while(i>0){ now=j; while(now>0){ ans+=tree[i][now]; now-=lowbit(now); } i-=lowbit(i); } return ans;}int main(){ int i,j,k,p,q,s; bool flag; while(scanf("%d%d",&n,&m)!=EOF){ memset(tree,0,sizeof(tree)); flag=false; s=0; for(i=1;i<=n;i++) for(j=1;j<=n;j++){ scanf("%d",&first[i][j]); if(first[i][j]) update(i,j); } for(i=1;i<=m;i++) for(j=1;j<=m;j++){ scanf("%d",&second[i][j]); s+=second[i][j]; } if(n<m){ printf("No\n"); continue; } k=n-m+2; for(i=1;i<k;i++) for(j=1;j<k;j++){ if(sum(i+m-1,j+m-1)-sum(i-1,j+m-1)-sum(i+m-1,j-1)+sum(i-1,j-1) != s) continue; for(p=1;p<=m;p++) for(q=1;q<=m;q++){ if(first[i+p-1][j+q-1]!=second[p][q]) p=m+2,q=m+2;//printf("OO"); } // if(p!=m+3 && q!=m+3) flag=true,i=k,j=k; } if(flag){ printf("Yes\n"); }else{ printf("No\n"); } } return 0;}
- HDU 3531 Match(树状数组)
- bzoj 1264 [AHOI2006]基因匹配Match(DP+树状数组)
- bzoj 1264: [AHOI2006]基因匹配Match (DP+树状数组)
- BZOJ 1264 Match 基因匹配 (dp 树状数组优化)
- bzoj 1264: [AHOI2006]基因匹配Match(树状数组)
- hdu (3874)树状数组
- hdu 2352(树状数组)
- HDU 1556(树状数组)
- hdu 5493 (树状数组)
- HDU 4911 (树状数组)
- 树状数组(hdu 1166)
- HDU 1394 (树状数组)
- HDU 4267 (树状数组)
- hdu 4031(树状数组+辅助数组)
- 【bzoj1264】【基因匹配Match】【dp+树状数组】
- HDU 3525(树状数组求解LCS)
- HDU-1541 树状数组(基础题)
- hdu 1892(二维树状数组模板)
- C语言连接数据库
- 1010:平均绩点
- leetcode-Binary Tree Zigzag Level Order Traversal
- Genesis-3D 入门教程—18.基本UI及运行
- Java备忘录模式(Memento)
- HDU 3531 Match(树状数组)
- 快速傅里叶变换(蝶形算法)
- JavaWeb开发中遇到的错误:org.apache.catalina.core.StandardWrapperValve invoke
- CPtrList操作(插入,删除特定元素,删除全部)
- 语音识别工具箱之kaldi介绍
- 1013:摆积木
- Genesis-3D 入门教程—19.场景水
- cocos
- 使用AlertDialog.Builder自定义对话框