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,其余点的值为点到中心点的曼哈顿距离. ...
随机推荐
- Docker 编排工具Rancher 2.0
下载镜像: [root@localhost hongdada]# docker pull rancher/server:preview 运行容器: [root@localhost hongdada]# ...
- try finally 执行顺序问题
有return的情况下try catch finally的执行顺序 在遇到Exception 并且没有catch的情况下finally语句块没有执行 System.exit(0),终止了 Java 虚 ...
- oracle函数之 minus
“minus”直接翻译为中文是“减”的意思,在Oracle中也是用来做减法操作的 Oracle的minus是按列进行比较的,所以A能够minus B的前提条件是结果集A和结果集B需要有相同的列数,且相 ...
- oracle 之 基础操作
//删除存在的表空间及数据 drop tablespace TS_YYGL including contents and datafiles 若是出现了提示 错误 导致无法全部删除,那么就执行以下语句 ...
- Ubuntu18.04安装Android Studio
一.安装JDK JDK下载地址:https://www.oracle.com/technetwork/java/javase/downloads/jdk11-downloads-5066655.htm ...
- Twenty score
1.上图中有两个人对读书的看法有较大的不同. There are two people in the cartoon who treat books in completely different w ...
- Node内核基本自带模块fs 文件的读写
在node的内核中存在一些内置的模块 这些是最基本的服务端所必要的 1:node全局环境:global类似于浏览器端的window 2:文件读取模块:fs fs模块同时提供了异步和同步的方法. 'us ...
- RN原生调用一:安卓Toast
首先安卓原生方法:Toast.makeText(getApplicationContext(), "默认的Toast", Toast.LENGTH_SHORT); 在RN中js如何 ...
- 使用CSS渐变
转载自:https://developer.mozilla.org/zh-CN/docs/Web/Guide/CSS/Using_CSS_gradients CSS 渐变 是在 CSS3 Image ...
- crontab 定时执行python脚本
每天8点30分运行命令/tmp/run.sh * * * /tmp/run.sh 每两小时运行命令/tmp/run.sh */ * * * /tmp/run.sh