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的更多相关文章

  1. Codeforces Round #495 (Div. 2) C. Sonya and Robots

    http://codeforces.com/contest/1004/problem/C 题意: 在一行上有n个数字,现在在最左边和最右边各放置一个机器人,左右机器人各有一个数字p和q.现在这两个机器 ...

  2. Codeforces Round #524 (Div. 2) E. Sonya and Matrix Beauty(字符串哈希,马拉车)

    https://codeforces.com/contest/1080/problem/E 题意 有一个n*m(<=250)的字符矩阵,对于每个子矩阵的每一行可以任意交换字符的顺序,使得每一行每 ...

  3. Codeforces Round #495 (Div. 2) Sonya and Matrix

    正常没有正方形的限制下,值为i的点个数4i 那么从0开始遍历,第一个不为4i的值就是min(x, y) 由于对称性我们姑且令x为这个值 我们先列举n*m=t的各种情况 对于一对n, m.我们已经知道n ...

  4. Codeforces Round #495 (Div. 2) B

    题目链接:http://codeforces.com/contest/1004/problem/B B. Sonya and Exhibition time limit per test 1 seco ...

  5. 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 ...

  6. Codeforces Round #371 (Div. 2) C. Sonya and Queries 水题

    C. Sonya and Queries 题目连接: http://codeforces.com/contest/714/problem/C Description Today Sonya learn ...

  7. 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 ...

  8. 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 ...

  9. 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 ...

随机推荐

  1. java爬取网站信息和url实例

    https://blog.csdn.net/weixin_38409425/article/details/78616688(出自此為博主) 具體代碼如下: import java.io.Buffer ...

  2. elk-filebeat-(效果图示)(四)

    一.vim filebeat-6.3.2-linux-x86_64/filebeat.yml - type: log # Change to true to enable this input con ...

  3. php三级联动(html,php两个页面)

    <!doctype html><html><head><meta charset="utf-8"><title>无标题文 ...

  4. partial_sum

    版本1: template < class InputIterator, class OutputIterator > OutputIterator partial_sum(InputIt ...

  5. 如何查看.net framework 版本

    以windows 2016 standard版本为例 通过注册表查看,找到 .NET Framework 注册表信息所在的位置:HKEY_LOCAL_MACHINE\SOFTWARE\Microsof ...

  6. [04-01]css组合选择器

    /* 私人笔记 */   组合选择器:把基本选择器通过特殊符号串在一起,可以带来一些特殊的意义: 1.源码 <!DOCTYPE html> <html lang="zh&q ...

  7. [java] 在linux+chrome/firefox上使用java applet

    我现在的浏览器用不了java applet,我的环境是archlinux + chrome or firefox. java网站的指引是这样说的 按照这些说明操作,以便在 Ubuntu Linux 上 ...

  8. Linux更新时,出现无法更新锁

    1.查看软件中心是否有更新 2.重启 3.rm/var/lib/dpkg/lock 4.sudo apt-get update 5.sudo dpkg --configure -a

  9. 第九篇——Struts2的拦截器

    拦截器: Struts2大多数核心功能都是通过拦截器实现的,每个拦截器完成某项功能: 拦截器方法在Action执行之前或之后执行. 工作原理: 拦截器的执行过程是一个递归的过程 action请求--& ...

  10. (Review cs231n) BN and Activation Function

    CNN网络的迁移学习(transfer learning) 1.在ImageNet上进行网络的预训练 2.将最上方的层,即分类器移除,然后将整个神经网络看成是固定特征提取器来训练,将这个特征提取器置于 ...