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 ...
随机推荐
- Scrapy框架基本使用
pycharm+Scrapy 距离上次使用Scrapy已经是大半年前的事情了,赶紧把西瓜皮捡回来.. 简单粗暴上爬取目标: 初始URL:http://quotes.toscrape.com/ 目标:将 ...
- JS实现表格使用上下左右键聚集
//调用:new tabTableInput("tblGrid","text"); var tabTableInput = function (tableId, ...
- itoa()、atoi()、任意进制转换
头文件:<stdlib.h> itoa --功能:将任意类型的数字转换为字符串.在<stdlib.h>中与之有相反功能的函数是atoi. atoi----功 能: 将字符串转换 ...
- css学习_css常见属性用法
1.元素的显示模式 a.被动转换:浮动.绝对定位.固定定位(转换为行内块元素特性的模式---不设置宽度时,模式换行为行内块模式后宽度是内容宽度.) b.主动转换:display:block / in ...
- nginx笔记 安装nginx 配置 反向代理 多虚拟主机
1,检测linux上是否 通过yum安装了nginxrpm -qi nginx 2.安装nginx之前的依赖包yum install gcc patch libffi-devel python- ...
- java Int 和 String 之间的转换
String 转换成 int Integer.parseInt(formParams.get("id")) int 转换成 string Integer.toString(id);
- 15.0-uC/OS-III资源管理
1.共享资源可以是:变量(静态的或全局的).结构体.内存空间. I/O等. 多个任务可能会同时要求占用资源: 内存空间. 全局变量. 指针.缓冲区. 列表. 环形缓冲区等. 通过共享资源, 任务间通信 ...
- selenium定位下拉框
下拉选择框(Select) <div> <p>下拉选择框框 Select</p> <select id="proAddItem_kind" ...
- java框架之SpringBoot(16)-分布式及整合Dubbo
前言 分布式应用 在分布式系统中,国内常用 Zookeeper + Dubbo 组合,而 SpringBoot 推荐使用 Spring 提供的分布式一站式解决方案 Spring + SpringBoo ...
- python基础之 数据类型的补充,小数据类型
1.id is详解 ID 在Python中,id是什么?id是内存地址,比如你利用id()内置函数去查询一个数据的内存地址: name = 'nba' print(id(name)) # 158583 ...