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. 转载:Systemd 服务配置文件

    目录 一.开机启动 二.启动服务 三.停止服务 四.读懂配置文件 五. [Unit] 区块:启动顺序与依赖关系. 六.[Service] 区块:启动行为 6.1 启动命令 6.2 启动类型 6.3 重 ...

  2. oracle 之 统计函数、子查询、操作符

    统计函数 COUNT():查询表中的数据记录 AVG():求出平均值 SUM():求和 MAX():求出最大值 MIN():Q求出最小值 子查询   [单行多列] select * from a wh ...

  3. (转) RNN models for image generation

    RNN models for image generation MARCH 3, 2017   Today we’re looking at the remaining papers from the ...

  4. BZOJ 4399 魔法少女LJJ(线段树合并)

    题意 https://www.lydsy.com/JudgeOnline/problem.php?id=4399 思路 码农题,需要一定代码功底.方法很暴力,先将权值离散,表示在线段树里储存的位置,每 ...

  5. HDU 5245 Joyful(期望)

    http://acm.hdu.edu.cn/showproblem.php?pid=5245 题意: 给出一个n*m的矩阵格子,现在有k次操作,每次操作随机选择两个格子作为矩形的对角,然后将这范围内的 ...

  6. 使用explain来分析SQL语句实现优化SQL语句

    用法:explain sql 作用:用于分析sql语句 mysql> explain select * from quser_1 where loginemail = "quctest ...

  7. JMeter中关于动态切换不同CSV文件解决方案

    最近写case,需要当前播放节目的数据作为输入数据,所以每个时刻所用的数据只能是当前时刻附件的数据,尝试用CSV Data Set Config动态加载不同的文件,没有成功,好像CSV Data Se ...

  8. C#判断数据类型的简单示例代码

    ; Console.WriteLine( "i is an int? {0}",i.GetType()==typeof(int)); Console.WriteLine( &quo ...

  9. 关于在mac安装安卓的模拟器的一些些那点事情~~~

    ook~~自己捣鼓了三天终于安装成功了~妹的~踩了太多的坑~整个人就不好了~ 为了节省大家的时间~所以今天我就将我安装的过程整体思路教给大家!有了思路安装起来就很好了!!!但是 注意的是,也许你会出现 ...

  10. JSON平铺功能的实现(JS操作JSON数据)

    一.什么是JSON平铺 JSON平铺分成两种: 平铺的json转树结构的json 例如: { a: 'value', b: 'b1.value' } // 转换成=> { a: 'value', ...