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. 【做题】cf603E——线段树分治

    首先感谢题解小哥,他在标算外又总结了三种做法. 此处仅提及最后一种做法. 首先考虑题目中要求的所有结点度数为奇数的限制. 对于每一个联通块,因为所有结点总度数是偶数,所以总结点数也必须是偶数的.即所有 ...

  2. hdu5628 Clarke and math

    题目地址 题目链接 题意 求 \[ g(i)=\sum_{i1|i}\sum_{i_2|i_1}\sum_{i_3|i_2}...\sum_{i_k|i_{k-1}}f(i_k)\space mod\ ...

  3. 论文笔记之:Natural Language Object Retrieval

    论文笔记之:Natural Language Object Retrieval 2017-07-10  16:50:43   本文旨在通过给定的文本描述,在图像中去实现物体的定位和识别.大致流程图如下 ...

  4. [LightOJ 1341] Aladdin and the Flying Carpet (算数基本定理(唯一分解定理))

    题目链接: https://vjudge.net/problem/LightOJ-1341 题目描述: 问有几种边长为整数的矩形面积等于a,且矩形的短边不小于b 算数基本定理的知识点:https:// ...

  5. pyqt5 窗口无边框和透明

    https://blog.csdn.net/FanMLei/article/details/79433229 按钮圆形方法属性border-radius:30px; QScrollArea 无法滚动用 ...

  6. 线性判别分析(Linear Discriminant Analysis-LDA)

    Linear Discriminant Analysis(LDA线性判别分析) 用途:数据预处理中的降维,分类任务 目标:LDA关心的是能够最大化类间区分度的坐标轴成分,将特征空间(数据集中的多维样本 ...

  7. Maven Web项目解决跨域问题

    跨域问题目前笔者所用到的方案大致有三种:jsonp,SpringMVC 4以上注解方式和cros三方过滤器. Jsonp JSONP(JSON with Padding)是一个非官方的协议,它允许在服 ...

  8. python requests post和get

    import requests import time import hashlib import os import json from contextlib import closing impo ...

  9. go helloworld

    // Sample program to show how a bytes.Buffer can also be used // with the io.Copy function. package ...

  10. 【C#】 基于ArcFace 2.0—视频人脸识别Demo

    使用的虹软人脸识别技术 啥话不说,不用跪求,直接给下载地址:http://common.tenzont.com/comdll/arcface2demo.zip(话说附件的大小不限制,还是说我的文件太大 ...