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. BZOJ4455 小星星

    闲扯 看到多个限制条件的计数题目,就想到容斥原理 思路 题目要求两个条件 - 编号一一对应 - 树上存在的边,在图上映射到的点上也应该存在 考虑一个暴力的dp,设\(dp_{i,j}\)表示i点编号对 ...

  2. 【译】第9节---EF Code First中数据注解

    原文:http://www.entityframeworktutorial.net/code-first/dataannotation-in-code-first.aspx EF Code-First ...

  3. K-近邻

    概述 KNN算法本身简单有效,是一种lazy-learning算法: 分类器不需要使用训练集进行训练,训练时间复杂度为0: KNN分类的计算复杂度和训练集中的文档数目成正比,也就是说,如果训练集中文档 ...

  4. jqGrid API (转)

    来源:https://www.cnblogs.com/MonaSong/p/5109991.html JQGrid是一个在jquery基础上做的一个表格控件,以ajax的方式和服务器端通信. JQGr ...

  5. Python 学习笔记 多进程 multiprocessing--转载

    本文链接地址 http://quqiuzhu.com/2016/python-multiprocessing/ Python 解释器有一个全局解释器锁(PIL),导致每个 Python 进程中最多同时 ...

  6. Centos6.8安装redis(一)

    最近有在学习会话共享的配置,其中一种呢是 nginx+redis+tomcat 的会话共享配置,在记录此会话共享配置之前呢先记录下redis等的安装.这篇先简单记录下redis的安装,是其中一种方式, ...

  7. PHP Warning: Module 'memcache' already loaded in Unknown on line 0

    出现类似PHP Warning: Module * already loaded in Unknown on line 0,一般是可能因为升级php导致的组件重复加载,解决就是 1.vi /etc/p ...

  8. SpringBoot配置Aop demo

    1. Demo部分 package com.example.demo.controller; import org.springframework.web.bind.annotation.Reques ...

  9. 2.0 vue内置指令与自定义指令

    1.1 常用内置指令 1) v:text : 更新元素的 textContent 2) v-html : 更新元素的 innerHTML 3) v-if : 如果为 true, 当前标签才会输出到页 ...

  10. Eclispe中编辑xml配置文件时不会提示也不能自动调整格式

    创建了一个xml文件后,发现编辑起来和原来的那些有所不同,不会提示补全.也不能自动调整格式???woc? 哈哈哈哈哈,“我最恨你像个石头一样” 后来发现是编辑器被改了!!! 右键xml文件然后open ...