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 ...
随机推荐
- 事务之五:Spring @Transactional工作原理
本文将深入研究Spring的事务管理.主要介绍@Transactional在底层是如何工作的. JPA(Java Persistence API--java持久层)和事务管理 很重要的一点是JPA本身 ...
- rails Ajax--利用Jquery
view function init_tree(product_name) { var htmlobj=$.ajax({url: "get_all_file?param=" + p ...
- sql查询将列里面的值替换为别的值但是实际值不变
数据库有一张表BUG(缺陷记录表) 里面有字段severity(严重程度): severity的值实际为1,2,3,4,但希望在查询结果中将severity的1,2,3,4值显示为其他的值,但seve ...
- 配置IIS服务:无法找到该页 您正在搜索的页面可能已经删除、更名或暂时不可用。
1.配置IIS服务器时,在默认网站创建虚拟目录XXX.然后右击启动页面.aspx,“浏览” 2. 出现错误: 无法找到该页 您正在搜索的页面可能已经删除.更名或暂时不可用. ------------ ...
- numpy.zeros(shape, dtype=float, order='C')
numpy.zeros Return a new array of given shape and type, filled with zeros. Parameters: shape : int o ...
- 5、bam格式转为bigwig格式
1.Bam2bigwig(工具) https://www.researchgate.net/publication/301292288_Bam2bigwig_a_tool_to_convert_bam ...
- SDK和JDK的区别
刚开始工作时,还以为两者是一样的,只是版本换新给了个新名字罢了.最近又关注到这个问题,才发现自己大错特错,故整理了下分享给大家,共勉! jdk,是Java开发工具包,主要用于编写Java程序:也就是说 ...
- JSP错误页面
exception是JSP九大内置对象之一,其实例代表其他页面的异常和错误.只有当页面是错误处理页面时,即isErroePage为 true时,该对象才可以使用.对于C项,errorPage的实质就是 ...
- 数据库 连接(join)
转自http://www.cnblogs.com/caozengling/p/5318696.html 数据库中飞内连接,自然连接,外连接 数据库中的连接join氛围内连接,自然连接,外连接,外连接又 ...
- ajax的回调函数和匿名函数
1.什么是js回调函数 一. 回调函数的作用 js代码会至上而下一条线执行下去,但是有时候我们需要等到一个操作结束之后再进行下一个操作,这时候就需要用到回调函数. 二. 回调函数的解释 因为函数实际上 ...