题目大意:选取1-k 以内的数填入方格中,使满足的等号和不等号的个数>=3/4
如果K 大于等于2的话,其实我们可以只用1,2 来填,因为他有列之间的关系矩阵,和行之间的关系矩阵,所以我们考虑先满足较大的矩阵关系,然后再去判段另一个矩阵的关系。如果某一列(或某一行,看是什么矩阵)满足条件的个数小于一半的话,就把这一列取反(1变2,2变1),因为关系是相对的,所以之前满足的矩阵依然满足。总之,挺麻烦的,一定要想清楚了再写。。。。
#include<iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<cmath>
#define N 2003
using namespace std;
int m,n,k;
int a[N][N],b[N][N],cnta,cntb;
int ans[N][N];
int main()
{
//freopen("a.in","r",stdin);
scanf("%d%d%d",&n,&m,&k);
for (int i=1;i<=n+n-1;i++)
{
char s[1003]; scanf("%s",s+1);
if (i&1) {
++cnta;
for (int j=1;j<=m-1;j++)
if (s[j]=='N') a[cnta][j]=1;
}
else{
++cntb;
for (int j=1;j<=m;j++)
if (s[j]=='N') b[cntb][j]=1;
}
}
/*for (int i=1;i<=n;i++)
{
for (int j=1;j<=m-1;j++)
cout<<a[i][j]<<" ";
cout<<endl;
}
for (int i=1;i<=n-1;i++)
{
for (int j=1;j<=m;j++)
cout<<b[i][j]<<" ";
cout<<endl;
} */
if (k==1){
for (int i=1;i<=n;i++)
for (int j=1;j<=m;j++) ans[i][j]=1;
int t=0;
for (int i=1;i<=n;i++)
{
for (int j=2;j<=m;j++)
if((ans[i][j-1]^ans[i][j])==a[i][j-1]||((ans[i][j-1]^ans[i][j])!=0&&a[i][j-1]))
t++;
}
for (int i=1;i<=m;i++)
{
for (int j=2;j<=n;j++)
if ((ans[j-1][i]^ans[j][i])==b[j-1][i]||((ans[j-1][i]^ans[j][i])!=0&&b[j-1][i]))
t++;
}
if (4*t>3*(n*(m-1)+(n-1)*m)) {
printf("YES\n");
for (int i=1;i<=n;i++)
{
for (int j=1;j<=m;j++)
if (!ans[i][j]) printf("2 ");
else printf("%d ",ans[i][j]);
printf("\n");
}
}
else printf("NO\n");
return 0;
}
if (n*(m-1)<=(n-1)*m){
for (int i=1;i<=m;i++)
{
for (int j=1;j<=n;j++)
{
if (j==1) ans[j][i]=1;
else if (!b[j-1][i]) ans[j][i]=ans[j-1][i];
else ans[j][i]=ans[j-1][i]^1;
}
}
for (int i=2;i<=m;i++)
{
int t=0;
for (int j=1;j<=n;j++)
if((ans[j][i-1]^ans[j][i])==a[j][i-1]||((ans[j][i]^ans[j][i-1])!=0&&a[j][i-1]))
t++;
int mid=(n+1)/2;
if (t<mid)
for (int j=1;j<=n;j++) ans[j][i]=ans[j][i]^1;
}
}
else
{
for (int i=1;i<=n;i++)
{
for (int j=1;j<=m;j++)
{
if (j==1) ans[i][j]=1;
else if (!a[i][j-1]) ans[i][j]=ans[i][j-1];
else ans[i][j]=ans[i][j-1]^1;
}
}
for (int i=2;i<=n;i++)
{
int t=0;
for (int j=1;j<=m;j++)
if ((ans[i][j]^ans[i-1][j])==b[i-1][j]||((ans[i][j]^ans[i-1][j])!=0&&b[i-1][j]))
t++;
int mid=(m+1)/2;
if (t<mid)
for (int j=1;j<=m;j++) ans[i][j]=ans[i][j]^1;
}
}
printf("YES\n");
for (int i=1;i<=n;i++)
{
for (int j=1;j<=m;j++)
if (!ans[i][j]) printf("2 ");
else printf("%d ",ans[i][j]);
printf("\n");
}
}