zoukankan      html  css  js  c++  java
  • 洛谷P1169 棋盘制作(悬线法)

    题目链接:https://www.luogu.org/problemnew/show/P1169

    #include<bits/stdc++.h>
    #define fi first
    #define se second
    #define INF 0x3f3f3f3f
    #define fio ios::sync_with_stdio(false);cin.tie(0);cout.tie(0)
    #define pqueue priority_queue
    #define NEW(a,b) memset(a,b,sizeof(a))
    const double pi=4.0*atan(1.0);
    const double e=exp(1.0);
    const int maxn=1e6+8;
    typedef long long LL;
    typedef unsigned long long ULL;
    const LL mod=1e9+7;
    const ULL base=1e7+7;
    using namespace std;
    int a[2008][2008];
    int l[2008][2008],r[2008][2008],u[2008][2008];
    int main(){
        int n,m;
        scanf("%d%d",&n,&m);
        for(int i=1;i<=n;i++){
            for(int j=1;j<=m;j++){
                scanf("%d",&a[i][j]);
            }
            l[i][1]=1;r[i][m]=m;
            for(int j=2;j<=m;j++){
                if(a[i][j]!=a[i][j-1]){
                    l[i][j]=l[i][j-1];
                }
                else{
                    l[i][j]=j;
                }
            }
            for(int j=m-1;j>=1;j--){
                if(a[i][j]!=a[i][j+1]){
                    r[i][j]=r[i][j+1];
                }
                else{
                    r[i][j]=j;
                }
            }
        }
        int maxa=0,maxb=0;
        for(int i=1;i<=n;i++){
            for(int j=1;j<=m;j++){
                if(i>1&&a[i][j]!=a[i-1][j]){
                    u[i][j]=u[i-1][j]+1;
                    l[i][j]=max(l[i][j],l[i-1][j]);
                    r[i][j]=min(r[i][j],r[i-1][j]);
                }
                else{
                    u[i][j]=1;
                }
                maxa=max(maxa,(r[i][j]-l[i][j]+1)*u[i][j]);
                maxb=max(maxb,min(r[i][j]-l[i][j]+1,u[i][j])*min(r[i][j]-l[i][j]+1,u[i][j]));
            }
        }
        cout<<maxb<<endl<<maxa<<endl;
    }
  • 相关阅读:
    分词器下载地址
    solr 查询方式
    solr 到 lucene
    Solr 安装与使用 Centos7
    线性表-串:KMP模式匹配算法
    金山——弱智的翻译程序
    FL2440移植Linux2.6.33.7内核
    FL2440移植u-boot2011.09
    【转】C/C++除法实现方式及负数取模详解
    循环缓冲类
  • 原文地址:https://www.cnblogs.com/Profish/p/9739229.html
Copyright © 2011-2022 走看看