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. Python学习之旅(十)

    Python基础知识(9):函数(Ⅰ) Python中函数的定义:是逻辑结构和过程化的一种编程方法 定义方法: def test(x): #def:定义函数的关键字 test:函数名 x:形参,也可以 ...

  2. Luogu 1071 - 潜伏者 - [字符串]

    题目链接:https://www.luogu.org/problemnew/show/P1071 题解: 模拟就完事儿了. 注意failed的情况有:出现一个 $f[x]$ 对应多个值:存在两个不同的 ...

  3. Codeforces 607A - Chain Reaction - [DP+二分]

    题目链接:https://codeforces.com/problemset/problem/607/A 题意: 有 $n$ 个塔排成一行,第 $i$ 个激光塔的位置为 $a_i$,伤害范围是 $b_ ...

  4. [No0000197]Windows用户都应该知道的运行命令

    通过"运行"命令,运行Windows丰富工具的方法.如果您知道工具或任务的相应"运行"命令,那么您就知道访问所述工具或任务的最快方法. 以下是我们最喜欢的Run ...

  5. centos7磁盘在线扩容

    1.添加新磁盘 2.fdisk -l查看磁盘被识别的名称 3.如果输入fdisk -l命令没有找到新的磁盘,按下面步骤操作 1)进入到cd /sys/class/scsi_host/ 2)echo & ...

  6. sqlserver为不同数据库建立不同访问权限的帐号

    正式服务器中,为了安全.互不干扰,会给个DB库分配不同的账号,A库有ARead\AReadWrite\AOwn账号,B库有BRead\BReadWrite\BOwn账号.需要配置出来,甚至还能限制AR ...

  7. sql server创建windows账户

    --不要干坏事 sql server中使用xp_cmdshell --1.允许配置高级选项 GO RECONFIGURE GO --2.开启xp_cmdshell服务 RECONFIGURE GO - ...

  8. nghttp2 和nginx的实践

    主要参考https://bg2bkk.github.io/post/HTTP2%E7%9A%84%E5%AE%9E%E8%B7%B5%E8%BF%87%E7%A8%8B/,和https://fangp ...

  9. js页面路径拼接字符串进行参数传递

    页面路径拼接字符串进行参数传递: 参数传递页面: <style> input,button{ border: 1px solid red; } body { font-size:24px; ...

  10. DataGridView 访问任意行不崩溃

    int index= this.dataGridView1.rows.Add(); 先执行这行代码,然后访问任意行,不崩溃, 赋值不存在的行,只是不显示,或者无值. 什么原理呢? 一些其他 priva ...