Codeforces Round #495 (Div. 2) D. Sonya and Matrix
http://codeforces.com/contest/1004/problem/D
题意:
在n×m的方格中,选定一个点(x,y)作为中心点,该点的值为0,其余点的值为点到中心点的曼哈顿距离。
现在给出t个点的值,问是否可以确定一个由t个点组成的方格,方格中的值由这t个点组成,如果有,则任一输出一个方格的规模n、m和中心点的坐标x、y。
思路:
参考了https://blog.csdn.net/FSAHFGSADHSAKNDAS/article/details/80951796的题解。
#include<iostream>
#include<cstdio>
#include<algorithm>
#include<cstring>
using namespace std;
const int maxn = 1e6+; int mx, t, n, m, x, y, c[maxn], tmp[maxn]; int main()
{
//freopen("in.txt","r",stdin);
scanf("%d",&t);
for(int i=;i<t;i++)
{
int a; scanf("%d",&a);
mx = max(mx, a);
c[a]++;
}
for(int i=;i<=t;i++)
{
if(c[i]!=(i<<))
{
x = i;
break;
}
}
for(int n=;n<=t;n++)
{
m = t/n;
if(n*m!=t) continue;
y = n+m-x-mx;
memset(tmp,,sizeof(tmp));
for(int i=;i<=n;i++)
for(int j=;j<=m;j++)
{
int d = abs(x-i)+abs(y-j);
tmp[d]++;
}
bool flag = true;
for(int i=;i<=n+m;i++)
{
if(tmp[i]!=c[i]) {flag=false;break;}
}
if(flag)
{
printf("%d %d\n",n,m);
printf("%d %d\n",x,y);
return ;
}
}
puts("-1");
return ;
}
Codeforces Round #495 (Div. 2) D. Sonya and Matrix的更多相关文章
- Codeforces Round #495 (Div. 2) C. Sonya and Robots
http://codeforces.com/contest/1004/problem/C 题意: 在一行上有n个数字,现在在最左边和最右边各放置一个机器人,左右机器人各有一个数字p和q.现在这两个机器 ...
- Codeforces Round #524 (Div. 2) E. Sonya and Matrix Beauty(字符串哈希,马拉车)
https://codeforces.com/contest/1080/problem/E 题意 有一个n*m(<=250)的字符矩阵,对于每个子矩阵的每一行可以任意交换字符的顺序,使得每一行每 ...
- Codeforces Round #495 (Div. 2) Sonya and Matrix
正常没有正方形的限制下,值为i的点个数4i 那么从0开始遍历,第一个不为4i的值就是min(x, y) 由于对称性我们姑且令x为这个值 我们先列举n*m=t的各种情况 对于一对n, m.我们已经知道n ...
- Codeforces Round #495 (Div. 2) B
题目链接:http://codeforces.com/contest/1004/problem/B B. Sonya and Exhibition time limit per test 1 seco ...
- Codeforces Round #371 (Div. 1) C. Sonya and Problem Wihtout a Legend 贪心
C. Sonya and Problem Wihtout a Legend 题目连接: http://codeforces.com/contest/713/problem/C Description ...
- Codeforces Round #371 (Div. 2) C. Sonya and Queries 水题
C. Sonya and Queries 题目连接: http://codeforces.com/contest/714/problem/C Description Today Sonya learn ...
- Codeforces Round #371 (Div. 2) C. Sonya and Queries —— 二进制压缩
题目链接:http://codeforces.com/contest/714/problem/C C. Sonya and Queries time limit per test 1 second m ...
- Codeforces Round #371 (Div. 2)E. Sonya and Problem Wihtout a Legend[DP 离散化 LIS相关]
E. Sonya and Problem Wihtout a Legend time limit per test 5 seconds memory limit per test 256 megaby ...
- Codeforces Round #371 (Div. 2) C. Sonya and Queries[Map|二进制]
C. Sonya and Queries time limit per test 1 second memory limit per test 256 megabytes input standard ...
随机推荐
- Linux 下安装mysql 5.7
Linux 下安装mysql 5.7 本人首次安装时按照菜鸟教程的步骤一步一步来的,结果意外的是 装成5.6了,而且各种无厘头的问题,例如无法启动... 本文参照 大佬:‘这个名字想了很久~’ 的&l ...
- mybatis cloud not autowired
mybatis代码生成器生成的mapper在service引用的时候报cloud not autowired.... 即是在pom.xml中配置了不过滤mapper文件,报错还在 其实这不影响使用,但 ...
- PrimeNG之FileUpload
--文件上传是一个支持拖放,多文件上传,自动上传,进度跟踪和验证的上传. Import import {FileUploadModule} from 'primeng/primeng'; Gettin ...
- 《PHP - CGI/Fastcgi/PHP-FPM》
先说下我最近看到的一篇文章,哈哈哈,特别好玩. 一步步教你编写不可维护的 PHP 代码 之前一直知道 PHP 在 CGI 模式下运行.命令行下在 CLI 模式下运行. 但是 FPM 和 nginx 配 ...
- 目标检测(五)YOLOv1—You Only Look Once:Unified,Real-Time Object Detection
之前的目标检测算法大都采用proposals+classifier的做法(proposal提供位置信息,分类器提供类别信息),虽然精度很高,但是速度比较慢,也可能无法进行end-to-end训练.而该 ...
- Spring Boot 自动配置原理(精髓)
一.自动配置原理(掌握) SpringBoot启动项目会加载主配置类@SpringBootApplication,开启@EnableAutoConfiguration自动配置功能 @EnableAut ...
- 苹果cms安装及配置详细教程
听说这个好!php+mysql的 下载 http://www.maccms.com/down.html 下载之后解压到你的网站跟目录中,就像这个样子的 后台目录 然后重要的一步来了,在ftp工具上 ...
- 利用StateListDrawable给button动态设置背景
项目中,遇到相同样式的Button,只是stroke颜色不一样.为了实现一个,就得写两个shape文件,一个selector文件:多个还得重复写. 解决方法: 结合StateListDrawable给 ...
- linux下查看CPU、内存、磁盘信息
1.查看CPU信息# 总核数 = 物理CPU个数 X 每颗物理CPU的核数 # 总逻辑CPU数 = 物理CPU个数 X 每颗物理CPU的核数 X 超线程数 # 查看物理CPU个数cat /proc/c ...
- 029-IIS配置
安装IIS.部署网站(发布或者拷贝都可以).修改连接字符串,compilation设为false,删掉cs代码上传文件夹不给执行权限: 在iis管理器中找到上传文件夹,选择属性--执行权限,设置为“无 ...