[悬线法] BZOJ1057 [ZJOI2007]棋盘制作
2016-03-15 11:21
302 查看
当年是怎么把这道悬线法SB题漏掉没刷的
总之悬线法,刚好在省选前复习下
一开始愣是没看出来 诶 太弱
总之悬线法,刚好在省选前复习下
一开始愣是没看出来 诶 太弱
#include<cstdio> #include<cstdlib> #include<algorithm> using namespace std; inline char nc() { static char buf[100000],*p1=buf,*p2=buf; if (p1==p2) { p2=(p1=buf)+fread(buf,1,100000,stdin); if (p1==p2) return EOF; } return *p1++; } inline void read(int &x) { char c=nc(),b=1; for (;!(c>='0' && c<='9');c=nc()) if (c=='-') b=-1; for (x=0;c>='0' && c<='9';x=x*10+c-'0',c=nc()); x*=b; } inline int sqr(int x){ return x*x; } int n,m; int M[2005][2005]; int left[2005][2005],right[2005][2005],height[2005][2005]; int main() { freopen("t.in","r",stdin); freopen("t.out","w",stdout); read(n); read(m); for (int i=1;i<=n;i++) for (int j=1;j<=m;j++) read(M[i][j]); for (int i=1;i<=n;i++) { int l=1,r=1; while (l<=m) { while (r+1<=m && M[i][r]==M[i][r+1]^1) r++; for (int j=l;j<=r;j++) left[i][j]=l,right[i][j]=r; l=r=r+1; } } for (int j=1;j<=m;j++) left[0][j]=1,right[0][j]=m; for (int i=1;i<=n;i++) for (int j=1;j<=m;j++) if (i==1 || M[i][j]==M[i-1][j]^1) { height[i][j]=height[i-1][j]+1; left[i][j]=max(left[i][j],left[i-1][j]); right[i][j]=min(right[i][j],right[i-1][j]); } else height[i][j]=1; int ans1=0,ans2=0; for (int i=1;i<=n;i++) for (int j=1;j<=m;j++) { ans1=max(ans1,height[i][j]*(right[i][j]-left[i][j]+1)); ans2=max(ans2,sqr(min(height[i][j],(right[i][j]-left[i][j]+1)))); } printf("%d\n%d\n",ans2,ans1); return 0; }
相关文章推荐
- 杭电 HDU ACM 1698 Just a Hook(线段树 区间更新 延迟标记)
- 如何改变Erlang的当前工作路径
- Spiral Matrix II
- 一张很使用的屏幕密度对应尺寸图
- 使用android studio 小技巧文集
- 类型类 V.S. 桥接模式:撞衫不可怕,谁丑谁尴尬
- Android性能优化之常见的内存泄漏
- bootstrap的tree控件
- 192 - Word Frequency
- 剑指offer-两个链表的第一个公共节点
- LUA string库详解
- 网站的最大并发连接数
- 时间格式转换
- 对不可用for update 的数据库管理工具如何复制记录
- 计算两个日期相隔的天数(jodd)
- 通过Object类说明方法重载、方法重写、多态之间的关系
- 开发错误手册
- hdoj 1027 Ignatius and the Princess II(排列组合)
- Python函数中的函数(闭包)用法实例
- 编程常识