题意略。
思路:
有两个点要注意一下:
1.这个菱形矩阵是8对称的,也即可以是沿45°对角线对称。
2.菱形矩阵上的数字表明了这个点到中心0点的距离,这对于确定位置有帮助。
这个题目简直刷新人生观,这么暴力的做法也能过。。。。
#include<bits/stdc++.h> using namespace std; const int maxn = 1000005; int cnt[maxn],t; int temp[maxn]; int main(){ int x,maxx = 0; scanf("%d",&t); for(int i = 0;i < t;++i){ scanf("%d",&x); ++cnt[x]; maxx = max(x,maxx); } if(cnt[0] > 1){ printf("-1\n"); return 0; } for(x = 1;x <= maxx;++x){ if(cnt[x] / x != 4) break; } int y; int n,m; bool jud = false; for(n = 1;n <= t;++n){ if(t % n) continue; m = t / n; if(n + m - x - maxx >= 1){ y = n + m - x - maxx; jud = true; memset(temp,0,sizeof(temp)); for(int i = 1;i <= n;++i){ for(int j = 1;j <= m;++j){ int cur = abs(i - x) + abs(j - y); ++temp[cur]; } } for(int i = 1;i <= maxx;++i){ if(cnt[i] != temp[i]){ jud = false; break; } } if(jud) break; } } if(jud){ printf("%d %d\n%d %d\n",n,m,x,y); } else printf("-1\n"); return 0; }