zoukankan      html  css  js  c++  java
  • AtCoder Regular Contest 081 F

    题目传送门:https://arc081.contest.atcoder.jp/tasks/arc081_d

    题目大意:

    给定一个(n×m)的棋盘,棋盘上有一些黑点和白点,每次你可以选择一行或一列,将上面所有的颜色取反,问若干次操作后可以得到的最大全黑子矩阵面积


    首先我们可以发现,对于一个(2×2)的子矩阵,如果其内部的黑点个数不是偶数个,则这个子矩阵不能全部变成黑点,因此我们可以将所有黑点权值设为1,白点设为0,每个(2×2)子矩阵的左上角记录其内部的异或值

    然后我们就可以随便写了……具体看代码吧……

    /*program from Wolfycz*/
    #include<cmath>
    #include<cstdio>
    #include<cstring>
    #include<iostream>
    #include<algorithm>
    #define inf 0x7f7f7f7f
    using namespace std;
    typedef long long ll;
    typedef unsigned int ui;
    typedef unsigned long long ull;
    inline char gc(){
    	static char buf[1000000],*p1=buf,*p2=buf;
    	return p1==p2&&(p2=(p1=buf)+fread(buf,1,1000000,stdin),p1==p2)?EOF:*p1++;
    }
    inline int frd(){
    	int x=0,f=1; char ch=gc();
    	for (;ch<'0'||ch>'9';ch=gc())	if (ch=='-')	f=-1;
    	for (;ch>='0'&&ch<='9';ch=gc())	x=(x<<3)+(x<<1)+ch-'0';
    	return x*f;
    }
    inline int read(){
    	int x=0,f=1; char ch=getchar();
    	for (;ch<'0'||ch>'9';ch=getchar())	if (ch=='-')	f=-1;
    	for (;ch>='0'&&ch<='9';ch=getchar())	x=(x<<3)+(x<<1)+ch-'0';
    	return x*f;
    }
    inline void print(int x){
    	if (x<0)	putchar('-'),x=-x;
    	if (x>9)	print(x/10);
    	putchar(x%10+'0');
    }
    const int N=2e3;
    int v[N+10][N+10],Lf[N+10][N+10],Rg[N+10][N+10],Up[N+10][N+10];
    int main(){
    	int n=read(),m=read();
    	for (int i=1;i<=n;i++){
    		static char s[N+10];
    		scanf("%s",s+1);
    		for (int j=1;j<=m;j++)	v[i][j]=(s[j]=='#');
    	}
    	for (int i=1;i<=n;i++)	for (int j=1;j<=m;j++)	v[i][j]^=v[i+1][j]^v[i][j+1]^v[i+1][j+1];
    	int Ans=max(n--,m--);
    	for (int i=1;i<=n;i++){
    		for (int j=1;j<=m;j++)	Lf[i][j]=v[i][j]?0:Lf[i][j-1]+1;
    		for (int j=m;j>=1;j--)	Rg[i][j]=v[i][j]?0:Rg[i][j+1]+1;
    	}
    	memset(Lf[0],127,sizeof(Lf[0]));
    	memset(Rg[0],127,sizeof(Rg[0]));
    	for (int i=1;i<=n;i++){
    		for (int j=1;j<=m;j++){
    			if (v[i][j])	Up[i][j]=0,Lf[i][j]=Rg[i][j]=inf;
    			else{
    				Up[i][j]=Up[i-1][j]+1;
    				Lf[i][j]=min(Lf[i][j],Lf[i-1][j]);
    				Rg[i][j]=min(Rg[i][j],Rg[i-1][j]);
    				Ans=max(Ans,(Up[i][j]+1)*(Lf[i][j]+Rg[i][j]));
    			}
    		}
    	}
    	printf("%d
    ",Ans);
    	return 0;
    }
    
  • 相关阅读:
    eclipse中的Invalid text string (xxx).
    在jsp文件中出现Unknown tag (c:out)
    eclipse 界面复原
    ecilpse 纠错插件
    Multiple annotations found at this line:- The superclass "javax.servlet.http.HttpServlet" was not found on the Java Build Path
    Port 8080 required by Tomcat v9.0 Server at localhost is already in use. The server may already be running in another process, or a system process may be using the port.
    调用第三方https接口
    调用第三方http接口
    创建带值枚举
    spring整合redis之Redis配置文件
  • 原文地址:https://www.cnblogs.com/Wolfycz/p/10118591.html
Copyright © 2011-2022 走看看