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 ...
随机推荐
- HashSet的底层
今天看博客,发现有个哥哥写到 HashSet的底层是数组结构,有点懵逼,不是HashMap吗怎么成数组了? 遂去查了下源码: 得以下结论: HashSet底层是 HashMap,其元素是内部map的k ...
- Unity 为队伍设置不同颜色的shader
在魔兽争霸等一些游戏中,我们通过模型的颜色就能很轻松的区分队伍,如下: 实现的方法有很多,比如: 1,为不同队伍各出一张不同颜色的贴图(Hmmm,war3有的地图可以容纳12只队伍,美术大大们会很 ...
- js设计模式(六)---命令模式
命令模式算是最简单.优雅的模式之一了,命令模式中的命令指的是一个执行某些特定事情的指令.目的是吧请求发送者和请求接受者解耦, 就像点餐,顾客只需要发送菜单,谁去接收,不用考虑.厨师接收到命令开始做菜, ...
- vue-cli+webpack+router+vuex---之vuex使用
有信心的可以去看官方的文档 vue 的官方文档有个显著的特点---代码粘贴不全 Vue中文站:cn.vuejs.org vue-router官方教程:router.vuejs.org/zh-cn vu ...
- kubernetes组成
kubernetes组成 k8s主要包括: kubectl 客户端命令行工具: 将接收的命令,发送给kube-apiserver,作为对整个平台操作的入口. kube-apiserver REST A ...
- Java 批量下载excel,并对excel赋值,压缩为zip文件(POI版)
package com.neusoft.nda.servlet; import java.io.File;import java.io.FileInputStream;import java.io.F ...
- Herriott池的设计
0.矩阵法计算光路 1.谐振腔和透镜组的等效,计算x和x’ 2.近轴光路的近似计算和矩阵法. 3.相邻光线的角度 4.为啥分模式 5.椭圆模式 6.要考虑的其他问题,相邻光斑的干涉
- nginx笔记 安装nginx 配置 反向代理 多虚拟主机
1,检测linux上是否 通过yum安装了nginxrpm -qi nginx 2.安装nginx之前的依赖包yum install gcc patch libffi-devel python- ...
- Codeforces 1090B - LaTeX Expert - [字符串模拟][2018-2019 Russia Open High School Programming Contest Problem B]
题目链接:https://codeforces.com/contest/1090/problem/B Examplesstandard input The most famous characters ...
- MVCC&PURGE&分布式事务
Ⅰ.MVCC介绍 consistent non-locking read,通过行多版本控制的方式读取当前执行时间点的记录 默认情况下innodb select没有任何锁,读到的记录在更新就通过undo ...