Sonya and Matrix CodeForces - 1004D (数学,构造)
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 (数学,构造)的更多相关文章
- 【CodeForces】708 B. Recover the String 数学构造
[题目]B. Recover the String [题意]找到一个串s,满足其中子序列{0,0}{0,1}{1,0}{1,1}的数量分别满足给定的数a1~a4,或判断不存在.数字<=10^9, ...
- codeforces 1041 e 构造
Codeforces 1041 E 构造题. 给出一种操作,对于一棵树,去掉它的一条边.那么这颗树被分成两个部分,两个部分的分别的最大值就是这次操作的答案. 现在给出一棵树所有操作的结果,问能不能构造 ...
- 【题解】Sonya and Matrix Beauty [Codeforces1080E]
[题解]Sonya and Matrix Beauty [Codeforces1080E] 传送门:\(Sonya\) \(and\) \(Matrix\) \(Beauty\) \([CF1080E ...
- 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 ...
- codeforces 495D Sonya and Matrix
Since Sonya has just learned the basics of matrices, she decided to play with them a little bit. Son ...
- Codeforces Gym101341I:Matrix God(随机化构造矩阵降维)***
http://codeforces.com/gym/101341/problem/I 题意:给三个N*N的矩阵,问a*b是否等于c. 思路:之前遇到过差不多的题目,当时是随机行(点),然后验证,不满足 ...
- 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 ...
- 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 ...
- Codeforces Round #495 (Div. 2) D. Sonya and Matrix
http://codeforces.com/contest/1004/problem/D 题意: 在n×m的方格中,选定一个点(x,y)作为中心点,该点的值为0,其余点的值为点到中心点的曼哈顿距离. ...
随机推荐
- How Flyway works
The easiest scenario is when you point Flyway to an empty database. It will try to locate its schema ...
- 【问题解决】连接mysql 8错误:authentication plugin 'caching_sha2_password
在刚安装好mysql8,使用native连接的时候报错 authentication plugin 'caching_sha2_password'... 首先确保服务已开启,然后通过cmd命令进入my ...
- 好用的js模板
组织form下的 json对象 $.fn.serializeObject = function() { var o = {"unique_id":new Date().getTim ...
- 题解——洛谷P3812【模板】线性基
学了下线性基 使用好像并不复杂 打了板子 但是要注意位运算优先级 #include <cstdio> #include <algorithm> #include <cst ...
- (转)Awesome GAN for Medical Imaging
Awesome GAN for Medical Imaging 2018-08-10 09:32:43 This blog is copied from: https://github.com/xin ...
- Java中sort实现降序排序
利用Collections的reverseOrder方法: import java.util.Arrays; import java.util.Collections; public class Ma ...
- CSS sprites
CSS Sprites在国内很多人叫css精灵,是一种网页图片应用处理方式. 优点: 它允许你将一个页面涉及到的所有零星图片都包含到一张大图中去,这样一来,当访问该页面时,载入的图片就不会像以前那样一 ...
- git界面里面复制粘贴
git界面里常用的粘贴方法: 1.Insert键或者Fn+Insert键 2.右键或者shift+右键 Paste 粘贴 3.还有一些设置可以用,在git面板中(或者右键),点击option选项 这里 ...
- _spellmod_leech_aura
comment 备注 aura 光环ID,玩家有这个光环时候造成的伤害会转化成吸血效果 chance 每次伤害转化成吸血效果的几率 type 吸血的类型,数据库枚举类型,可以直接选取 base ...
- ImgQuoteUIWindow
using System;using UnityEngine;using UnityEngine.UI;using UnityEditor;using System.Collections;using ...