hdu 2830 Matrix Swapping II
来源:互联网 发布:网络语言的利与弊作文 编辑:程序博客网 时间:2024/04/30 10:18
http://acm.hdu.edu.cn/showproblem.php?pid=2830
先求出每一行的高度,然后对于每一行有多少个 存在高度 用个hash存起来
后面枚举的时候 先排序从大到小,然后 二维只枚举到hash存起来的数就行了,
排序是为了方便求对于每一行求矩阵且节省时间,因为0的就跳过了
矩阵求法 ans=max(height[i][j]*j,ans); 因为前面大的高度就能包含后面小的了所以这里乘以j
代码:
#include <stdio.h>#include <stdlib.h>#include <math.h>#include <string.h>#include <iostream>#include <algorithm>#include <map>#include <set>#include <queue>using namespace std;char matrix[1005][1005]={0};int num[1005][1005];int hashs[1005];int cmp(const int a,const int b){ return a>b;}int main(){ int n,m; while(scanf("%d%d",&n,&m)==2) { memset(num,0,sizeof(num)); memset(hashs,0,sizeof(hashs)); for(int i=1;i<=n;i++) scanf("%s",matrix[i]+1); for(int i=1;i<=n;i++) for(int j=1;j<=m;j++) { if(matrix[i][j]=='1') { if(num[i-1][j]) num[i][j]=num[i-1][j]+1; else num[i][j]++; hashs[i]++; } else num[i][j]=0; } int maxn=0; for(int i=1;i<=n;i++) { sort(num[i]+1,num[i]+1+m,cmp); for(int j=1;j<=hashs[i];j++) { maxn=max(num[i][j]*j,maxn); } } printf("%d\n",maxn); } return 0;}
- hdu 2830 Matrix Swapping II
- HDU 2830 Matrix Swapping II
- hdu 2830 Matrix Swapping II
- hdu 2830 Matrix Swapping II
- hdu 2830 Matrix Swapping II
- hdu 2830 Matrix Swapping II
- HDU 2830 Matrix Swapping II
- hdu 2830 Matrix Swapping II
- hdu 2830 - Matrix Swapping II
- HDU 2830 Matrix Swapping II
- HDU 2830 Matrix Swapping II
- hdu 2830 Matrix Swapping II
- hdu 2830 Matrix Swapping II
- hdu 2830 Matrix Swapping II
- HDU 2830 Matrix Swapping II *
- HDU 2830 Matrix Swapping II
- #HDU 2830 Matrix Swapping II
- hdu 2830 Matrix Swapping II
- acm_hdu_1.1 有感
- HostMonitor是一款功能强大的运维管理软件
- ACM足球赛
- 【笔试与面试】顶点软件群体面试
- twitter_bootstrap_第二章
- hdu 2830 Matrix Swapping II
- POJ 1050 DP
- VC控件使用小结
- Window7 + Vmware + Ubuntu : 上网和VmwareTools(菜鸟可以看看,因为是我这个菜鸟总结的)
- python-mysql基本用法
- 两个玻璃球和100层楼的问题
- 数组和指针
- java math.ceil() floor()
- 今年的百度站长们很湿灰心