Hyperspace Travel
https://www.hackerrank.com/contests/infinitum16-firsttimer/challenges/hyperspace-travel
给出n个点,是一个m维坐标,要求找一个点,使得这n个点到这个点的哈曼顿距离之和最小。输出字母序最小的一组解
考虑一维的时候,是很简单的,先把x排序,然后取中点就行,偶数的话取左边那个即可。
然而这是n维,但是是一样的,因为x和y是分开算的,什么意思呢?就是是固定的,对于一个点(x0,y0)去到(x1,y1),固定的是要走x1-x0步(x方向) y是固定走y1-y0步的,
所以x和y不互相影响,把m维拆开来算即可
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <algorithm>
using namespace std;
#define inf (0x3f3f3f3f)
typedef long long int LL; #include <iostream>
#include <sstream>
#include <vector>
#include <set>
#include <map>
#include <queue>
#include <string>
const int maxn = + ;
vector<int>pp[maxn];
void work() {
int n, m;
cin >> n >> m;
for (int i = ; i <= n; ++i) {
for (int j = ; j <= m; ++j) {
int x;
cin >> x;
pp[j].push_back(x);
}
}
for (int i = ; i <= m; ++i) {
sort(pp[i].begin(), pp[i].end());
}
int to = ;
if (n & ) {
for (int i = ; i <= m; ++i) {
// cout << pp[i][m / 2] << endl;
pp[to].push_back(pp[i][n / ]);
}
} else {
for (int i = ; i <= m; ++i) {
pp[to].push_back(pp[i][n / - ]);
}
}
for (int i = ; i < m - ; ++i) {
cout << pp[to][i] << " ";
}
cout << pp[to][m - ] << endl;
} int main() {
#ifdef local
freopen("data.txt","r",stdin);
#endif
work();
return ;
}
Hyperspace Travel的更多相关文章
- German Collegiate Programming Contest 2015(第三场)
Divisions David is a young boy and he loves numbers. Recently he learned how to divide two numbers.D ...
- 图论 - Travel
Travel The country frog lives in has nn towns which are conveniently numbered by 1,2,…,n. Among n(n− ...
- 【BZOJ-1576】安全路径Travel Dijkstra + 并查集
1576: [Usaco2009 Jan]安全路经Travel Time Limit: 10 Sec Memory Limit: 64 MBSubmit: 1044 Solved: 363[Sub ...
- Linux inode && Fast Directory Travel Method(undone)
目录 . Linux inode简介 . Fast Directory Travel Method 1. Linux inode简介 0x1: 磁盘分割原理 字节 -> 扇区(sector)(每 ...
- HDU - Travel
Problem Description Jack likes to travel around the world, but he doesn’t like to wait. Now, he is t ...
- 2015弱校联盟(1) - I. Travel
I. Travel Time Limit: 3000ms Memory Limit: 65536KB The country frog lives in has n towns which are c ...
- hdu 4666:Hyperspace(最远曼哈顿距离 + STL使用)
Hyperspace Time Limit: 20000/10000 MS (Java/Others) Memory Limit: 65535/65535 K (Java/Others)Tota ...
- ural 1286. Starship Travel
1286. Starship Travel Time limit: 1.0 secondMemory limit: 64 MB It is well known that a starship equ ...
- Travel Problem[SZU_K28]
DescriptionAfter SzuHope take part in the 36th ACMICPC Asia Chendu Reginal Contest. Then go to QingC ...
随机推荐
- 编译Python出现Tab,空格的问题
我们编译python代码时, 经常出现各种因为tab和空格的问题, 例如: IndentationError: unindent does not match any outer indentatio ...
- HDOJ1075字典翻译(map应用)
#include<iostream> #include<cstdio> #include<map> #include<string> #include& ...
- Trie(前缀树/字典树)及其应用
Trie,又经常叫前缀树,字典树等等.它有很多变种,如后缀树,Radix Tree/Trie,PATRICIA tree,以及bitwise版本的crit-bit tree.当然很多名字的意义其实有交 ...
- ssh-keygen和ssh-copy-id的简单使用
实验环境是CentOS7: ssh-keygen产生公钥和私钥对. ssh-copy-id:将本机的公钥使用ssh协议复制到远程的客户端,ssh协议的公钥和私钥一般存放于~/.ssh下 #主机 [ro ...
- Uva 213
1. 问题 第一次发现新的存储方式,int code[8][1<<8]; 用于存储二进制的形式 将字符以是十进制的方式存储到数组中 如何消除 \n \r 的影响,进行多行的输入 2. 代码 ...
- JS ES6 -- let命令
1.ES6新增了块级作用域的let和const 这新特性let命令,用来声明变量.它的用法类似于var,但是所声明的变量,只在let命令所在的代码块内有效. for循环的计数器,就很合适使用let命令 ...
- .net关于应用程序缓存的一些疑惑
疑惑:获取缓存后强制转换为实体对象传递给前台,如果前台对这个实体对象中属性更改的话缓存中的数据也随之改变,为啥??? 首先是创建缓存的方法: /// <summary> /// 创建缓存项 ...
- 我推荐的一些C\C++书籍
原文链接: 我推荐的一些C\C++书籍 人们常常问我有什么C++和编程的书籍推荐,也许是因为我在PowerDNS有一个关于"编写可读性良好的C++代码"的演讲.这篇博文可以作为我对 ...
- centos7 安装mysql 5.7多实例
一. Mysql多实例即一台服务器上运行多个Mysql服务进程 ,开启不同的服务端口,通过不同的socket 监听不同的服务端口来提供各自的服务. 二. Mysql多例有以下几个特点: 1. 有效利 ...
- 基本算法思想之递推算法思想(C++语言描述)
递推算法是非常常用的算法思想,在数学计算等场合有着广泛的应用.递推算法适合有明显公式规律的场合. 递推算法基本思想 递推算法是一种理性思维莫斯的代表,根据已有的数据和关系,逐步推到而得到结果.递推算法 ...