标签:main [] 链接 通过 宝宝 r++ line int str
#include<iostream> #include<cstdio> #include<algorithm> using namespace std; int a,b,n; int map[1010][1010]; int ans=0x3f3f3f3f; int main() { scanf("%d%d%d",&a,&b,&n); for(int i=1;i<=a;i++) for(int j=1;j<=b;j++) scanf("%d",&map[i][j]); for(int i=1;i+n-1<=a;i++) for(int j=1;j+n-1<=b;j++){ int maxx=0,minn=0x3f3f3f3f; for(int l=i;l<=n+i-1;l++) for(int r=j;r<=n+j-1;r++) maxx=max(maxx,map[l][r]), minn=min(minn,map[l][r]); ans=min(ans,maxx-minn); } printf("%d",ans); return 20020902; }
// luogu-judger-enable-o2 #pragma GCC optimize (2) #include<iostream> #include<cstdio> #include<algorithm> using namespace std; int a,b,n; int map[1010][1010]; int maxx[1010][1010]; int minn[1010][1010]; int ans=0x3f3f3f3f; int main() { scanf("%d%d%d",&a,&b,&n); for(int i=1;i<=a;i++) for(int j=1;j<=b;j++) scanf("%d",&map[i][j]), maxx[i][j]=minn[i][j]=map[i][j]; for(int k=2;k<=n;k++) for(int i=1;i+k<=a+1;i++) for(int j=1;j+k<=b+1;j++) maxx[i][j]=max(max(maxx[i][j],maxx[i+1][j+1]),max(maxx[i][j+1],maxx[i+1][j])), minn[i][j]=min(min(minn[i][j],minn[i+1][j+1]),min(minn[i][j+1],minn[i+1][j])), ans=k==n?min(ans,maxx[i][j]-minn[i][j]):0x3f3f3f3f; printf("%d",ans); return 0; } /* 5 4 2 1 2 5 6 0 17 16 0 16 17 2 1 2 10 2 1 1 2 2 2 */
标签:main [] 链接 通过 宝宝 r++ line int str
原文地址:https://www.cnblogs.com/cn-suqingnian/p/9412851.html