http://codeforces.com/contest/1004/problem/D

题意:网格图给定到中心点的曼哈顿距离数组, 求该图n,m及中心点位置

首先可以观察到距离最大值mx一定在某个角上, 可将它调整到位置(n,m)

设中心点(x, y) 则可以得到 n-x+m-y=mx

再注意到假若图无限大, 则对每个距离d的取值一定有4*d个

即第一个取值数<4*d的d可以调整为中心点的x坐标

然后就可以暴力枚举因子判断了

#include <iostream>
#include <cstdio>
#define REP(i,a,n) for(int i=a;i<=n;++i)
using namespace std;
const int N = 2e6+, INF = 0x3f3f3f3f;
int a, b, x, y, t;
int c[N], cnt[N]; int main() {
scanf("%d", &t);
REP(i,,t) {
scanf("%d", &x);
++c[x], b = max(b, x);
}
REP(i,,t) if (c[i]!=*i) {x=i;break;}
REP(i,,t) if (t%i==) {
int n=i, m=t/i;
y = n+m-x-b;
if (abs(n-x)+abs(m-y)!=b) continue;
REP(i,,n+m) cnt[i]=;
REP(i,,n) REP(j,,m) ++cnt[abs(x-i)+abs(y-j)];
int ok = ;
REP(i,,n+m) if (cnt[i]!=c[i]) {ok=;break;}
if (ok) {
printf("%d %d\n%d %d\n",n,m,x,y);
return ;
}
}
puts("-1");
}

Sonya and Matrix CodeForces - 1004D (数学,构造)的更多相关文章

  1. 【CodeForces】708 B. Recover the String 数学构造

    [题目]B. Recover the String [题意]找到一个串s,满足其中子序列{0,0}{0,1}{1,0}{1,1}的数量分别满足给定的数a1~a4,或判断不存在.数字<=10^9, ...

  2. codeforces 1041 e 构造

    Codeforces 1041 E 构造题. 给出一种操作,对于一棵树,去掉它的一条边.那么这颗树被分成两个部分,两个部分的分别的最大值就是这次操作的答案. 现在给出一棵树所有操作的结果,问能不能构造 ...

  3. 【题解】Sonya and Matrix Beauty [Codeforces1080E]

    [题解]Sonya and Matrix Beauty [Codeforces1080E] 传送门:\(Sonya\) \(and\) \(Matrix\) \(Beauty\) \([CF1080E ...

  4. Codeforces Round #397 by Kaspersky Lab and Barcelona Bootcamp (Div. 1 + Div. 2 combined) D. Artsem and Saunders 数学 构造

    D. Artsem and Saunders 题目连接: http://codeforces.com/contest/765/problem/D Description Artsem has a fr ...

  5. codeforces 495D Sonya and Matrix

    Since Sonya has just learned the basics of matrices, she decided to play with them a little bit. Son ...

  6. Codeforces Gym101341I:Matrix God(随机化构造矩阵降维)***

    http://codeforces.com/gym/101341/problem/I 题意:给三个N*N的矩阵,问a*b是否等于c. 思路:之前遇到过差不多的题目,当时是随机行(点),然后验证,不满足 ...

  7. Vasya And The Matrix CodeForces - 1016D (思维+构造)

    Now Vasya is taking an exam in mathematics. In order to get a good mark, Vasya needs to guess the ma ...

  8. Codeforces 715A. Plus and Square Root[数学构造]

    A. Plus and Square Root time limit per test 2 seconds memory limit per test 256 megabytes input stan ...

  9. Codeforces Round #495 (Div. 2) D. Sonya and Matrix

    http://codeforces.com/contest/1004/problem/D 题意: 在n×m的方格中,选定一个点(x,y)作为中心点,该点的值为0,其余点的值为点到中心点的曼哈顿距离. ...

随机推荐

  1. Linux配置ssh服务和XShell连接Linux

    SSH服务查看和安装,配置: https://www.cnblogs.com/qiuqiuqiu/p/6445426.html https://www.cnblogs.com/yunweis/p/77 ...

  2. 【字符串区别】SQLServer中char、varchar、nchar、nvarchar的区别:

    一.定义 char:    固定长度,存储ANSI字符,不足的补英文半角空格. nchar:   固定长度,存储Unicode字符,不足的补英文半角空格 varchar:  可变长度,存储ANSI字符 ...

  3. JQuery---高级类选择器

    1.ContentFilters 1.1 语法:$('div:contains(edu)').css('backgroundColor','yellow'); 只看div 本身是否包含内容 1.2 语 ...

  4. Latex: IEEEtrans模板下 扩大标题宽度

    参考: Extending side margins for Title section in IEEEtrans document class Latex: IEEEtrans模板下 扩大标题宽度 ...

  5. CSS-形变 动画 表格

    一.形变 /*1.形变参考点: 三轴交界点*/ transform-origin: x轴坐标 y轴坐标; ​ /*2.旋转 rotate deg*/ transform: rotate(720deg) ...

  6. Linux命令之locate命令

    1.locate locate 命令是文件搜索命令,它的搜索速度比 find 命令更快,原因在于它不搜索具体目录, 而是搜索一个数据库,这个数据库包含本地所有文件信息.Linux系统自动创建这个数据库 ...

  7. ImageConverter引起的 invalid address or address of corrupt block 0xb7feab58 passed to dlfree

    虹软人脸识别,其方法要传NV21格式的byte[], github上有一个虹软的Demo,是不是虹软工作人员写的不清楚,这个Demo里bitmap转NV21格式byte[]用的是一个第三方库https ...

  8. 牛客OI周赛4-提高组 A K小生成树(kmst)

    K小生成树(kmst) 思路: 暴力+并查集 枚举边的子集,用并查集判断两个点联不联通 代码: #include<bits/stdc++.h> using namespace std; # ...

  9. 大数据-Hive 常用命令

    Hive 启动 ~$ hive 退出 hive>quit; --退出hive or hive> exit; --exit会影响之前的使用,所以需要下一句kill掉hadoop的进程 > ...

  10. 雷林鹏分享:C# 方法

    C# 方法 一个方法是把一些相关的语句组织在一起,用来执行一个任务的语句块.每一个 C# 程序至少有一个带有 Main 方法的类. 要使用一个方法,您需要: 定义方法 调用方法 C# 中定义方法 当定 ...