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 ...
随机推荐
- Centos6.5安装上传下载工具
执行下面命令即可. sudo yum install lrzsz rz 是上传命令 sz filename是下载命令 如果rz上传文件时提示 was skipped,则用sudo rz命令来进行上传.
- Logstash 2.0.0 beta2 发布,开源日志管理
Logstash 是一个应用程序日志.事件的传输.处理.管理和搜索的平台.你可以用它来统一对应用程序日志进行收集管理,提供 Web 接口用于查询和统计. Logstash 现在是 ElasticSea ...
- 问题15:如何判断字符串a是否以字符串b开头或结尾
方法一:使用正则表达式的^和$实现 '^000':表示,只匹配字符串的开头,若开头是 '000' ,则返回 ['000'] : '000$':表示,只匹配字符串的结尾,若结尾是 '000' ,则返回 ...
- 问题:Oracle long 类型l;结果:oracle里long类型的总结
oracle里long类型的总结 1.LONG 数据类型中存储的是可变长字符串,最大长度限制是2GB. 2.对于超出一定长度的文本,基本只能用LONG类型来存储,数据字典中很多对象的定义就是用LONG ...
- jquery easyui 推荐博客 (MVC+EF+EasyUI+Bootstrap)
构建ASP.NET MVC5+EF6+EasyUI 1.4.3+Unity4.x注入的后台管理系统(52)-美化EasyUI皮肤和图标 系列目录 我很久以前就想更新系统的皮肤功能,Easyui 自 ...
- 请问两个div之间的上下距离怎么设置
转自:https://zhidao.baidu.com/question/344630087.html 楼上说的是一种方法,yanzilisan183 <div style="marg ...
- maven可用镜像
<mirrors> <mirror> <id>alimaven</id> <name>aliyun maven</name> & ...
- [HDU1711]KMP模板
解题关键:1.直接套kmp模板即可,注意最后输出的位置,需要在索引的位置+1. 2.next用作数组名在oj中会编译错误, 3.选用g++,只有g++才会接受bits/stdc++.h OJ中g++和 ...
- 杭电acm 1034题
Problem Description A number of students sit in a circle facing their teacher in the center. Each st ...
- Spring入门第六课
XML配置里的Bean自动装配 Spring IOC容器可以自动装配Bean.需要做的仅仅是在<bean>的autowire属性里指定自动装配的模式 ByType(根据类型自动装配):若I ...