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 = 100 + 20;
vector<int>pp[maxn];
void work() {int n, m;cin >> n >> m;for (int i = 1; i <= n; ++i) {for (int j = 1; j <= m; ++j) {int x;cin >> x;pp[j].push_back(x);}}for (int i = 1; i <= m; ++i) {sort(pp[i].begin(), pp[i].end());}int to = 104;if (n & 1) {for (int i = 1; i <= m; ++i) {
//            cout << pp[i][m / 2] << endl;pp[to].push_back(pp[i][n / 2]);}} else {for (int i = 1; i <= m; ++i) {pp[to].push_back(pp[i][n / 2 - 1]);}}for (int i = 0; i < m - 1; ++i) {cout << pp[to][i] << " ";}cout << pp[to][m - 1] << endl;
}int main() {
#ifdef localfreopen("data.txt","r",stdin);
#endifwork();return 0;
}

View Code

转载于:https://www.cnblogs.com/liuweimingcprogram/p/5873654.html

Hyperspace Travel相关推荐

  1. exam1802 Bounty Hunter II(DAG的最小路径覆盖)

    原文:http://www.cnblogs.com/jackiesteed/articles/2043934.html DAG的最小路径覆盖是指找最小数目的互相不相交的有向路径,满足DAG的所有顶点都 ...

  2. ASP.NET MVC 2示例Tailspin Travel

    Tailspin Travel 是一个旅游预订的应用程序示例,最新版本采用ASP.NET MVC 2技术构建,主要使用 DataAnnotations 验证, 客户端验证和ViewModels,还展示 ...

  3. 2018HDU多校训练-3-Problem G. Interstellar Travel

    链接:http://acm.hdu.edu.cn/showproblem.php?pid=6325                                  Interstellar Trav ...

  4. 四川第七届 I Travel(bfs)

    Travel The country frog lives in has nn towns which are conveniently numbered by 1,2,-,n1,2,-,n. Amo ...

  5. “人在旅途”之随想以及旅游指南(travel.msra.cn)简介

    首先让我们来回味马克.吐温说过的一句话: 旅行可以破除偏见.顽固以及狭隘的思想 稍微细想一下,这句话还是很有些道理的.很多时候,我们回头看看走过的路,难道不总是会有一种"人在旅途" ...

  6. Gym 100342I Travel Agency (Tarjan)

    题意读懂了就好做了,就是求一下点双连通分量.维护一下一颗子树的结点数,对于一个结点当u是割点的时候, 统计一下u分割的连通分量v,每得到一个连通分量的结点数cnt(v)和之前连通分量结点数sum相乘一 ...

  7. Jzoj3625 旅行(travel)

    非常好的树剖模板题了,直接C颗线段树上去就好了,动态开点一次写对~ #pragma GCC opitmize("O3") #pragma G++ opitmize("O3 ...

  8. UVA 617 - Nonstop Travel(数论+暴力枚举)

    题目链接:617 - Nonstop Travel 题意:给定一些红绿灯.如今速度能在30-60km/h之内,求多少个速度满足一路不遇到红灯. 思路:暴力每个速度,去推断可不能够,最后注意下输出格式就 ...

  9. ASP.NET MVC 2示例Tailspin Travel UI层分析

    Tailspin Travel 是一个旅游预订的应用程序示例,最新版本采用ASP.NET MVC 2技术构建,主要使用 DataAnnotations 验证, 客户端验证和ViewModels,还展示 ...

最新文章

  1. jsapi设计_一个简单API设计
  2. Mac自定义终端的欢迎页
  3. 粘贴铜箔高频实验板-简易电报发射机实验
  4. 图解TC++3.0开发教程
  5. sublime :[Decode error - output not utf-8]
  6. EcmaScript正則表達式( 深入淺出系列之淺出 )
  7. word List 21
  8. 数据库 事务隔离级别之可重复读
  9. 【linux】web socket
  10. 区分 WDM驱动和NT驱动(有待继续思考)
  11. NetSarang旗下网络通讯系列产品v5版本更新合集丨附下载
  12. 1055 集体照 (25分)
  13. 数据分析案例——航空公司客户价值分析
  14. 小程序关注公众号组件
  15. Visual Studio安装SVN过程及作用
  16. Java中如何给map数组制空,java.util.HashMap可以存储null键和null值。( )
  17. np.arange()用法,Python numpy.arange()用法
  18. 「制作U盘系统」”安装 Linux Ubuntu系统到移动硬盘“教程
  19. 秒懂Gradle之从完全懵逼到似懂非懂
  20. 如何写一个拼写纠错器 -- how to write a spelling corrector

热门文章

  1. mysql数据库切换
  2. Google Gson 使用简介
  3. 年年岁岁花相似,岁岁年年竟相同
  4. HttpSession
  5. React Native 环境配置
  6. 33.Node.js 文件系统fs
  7. 双11不过瘾?双十二低至半价继续抢,更有免费学的机会等你抢!
  8. 正则表达式入门及备忘
  9. R中rep函数的使用
  10. Android 通过腾讯WebService API获取 地址经纬度