给出n*m的矩阵,里面有一个坏点,不覆盖这个坏点的矩阵填满n*m的矩阵,使得这些矩阵的最大面积最小,并输出最小面积
先把矩阵转换为n<=m的矩阵,并把坏点通过镜像转移到左上方
ans=MAX(矩阵最中心点到两边距离的最小值,MIN(坏点下方的点到矩阵左端和下端的最小值));
#include "stdio.h" #include "string.h" int ans,n,m,x,y; int Max(int a,int b) { if (a<b) return b; else return a; } int Min(int a,int b) { if (a<b) return a; else return b; } int judge_1() { int sn,sm,mark; sn=n/2+1; sm=m/2+1; if (x>sn) x=n-x+1; if (y>sm) y=m-y+1; mark=n/2+1; if (x==sn && y==sm) return mark-1; else return Max(mark,Min(y,n-x)); } int judge_2() { int sn,sm,mark; sn=n/2; sm=m/2+1; if (x>sn) x=n-x+1; if (y>sm) y=m-y+1; mark=n/2; if (x==sn && y==sm) return mark; else return Max(mark,Min(y,n-x)); } int judge_3() { int sn,sm,mark; sn=n/2+1; sm=m/2; if (x>sn) x=n-x+1; if (y>sm) y=m-y+1; mark=n/2+1; if (x==sn && y==sm) return mark; else return Max(mark,Min(y,n-x)); } int judge_4() { int sn,sm,mark; sn=n/2; sm=m/2; if (x>sn) x=n-x+1; if (y>sm) y=m-y+1; mark=n/2; if (x==sn && y==sm) return mark; else return Max(mark,Min(y,n-x)); } int main() { int temp; while (scanf("%d%d%d%d",&n,&m,&x,&y)!=EOF) { if (n>m) { temp=n; n=m; m=temp; temp=x; x=y; y=temp;} if (n<=2) { printf("1\n"); continue; } if (n%2==1 && m%2==1) ans=judge_1(); if (n%2==0 && m%2==1) ans=judge_2(); if (n%2==1 && m%2==0) ans=judge_3(); if (n%2==0 && m%2==0) ans=judge_4(); printf("%d\n",ans); } return 0; }
版权声明:本文为博主原创文章,未经博主允许不得转载。
时间: 2024-10-11 11:30:59