2019牛客暑期多校训练营(第三场)H.Magic Line

题目链接

题目描述

There are always some problems that seem simple but is difficult to solve.

ZYB got N\ N N distinct points on a two-dimensional plane. He wants to draw a magic line so that the points will be divided into two parts, and the number of points in each part is the same. There is also a restriction: this line can not pass through any of the points.

Help him draw this magic line.

输入描述:

There are multiple cases. The first line of the input contains a single integer T(1≤T≤10000)T \ (1 \leq T \leq 10000)T (1≤T≤10000) , indicating the number of cases.

For each case, the first line of the input contains a single even integer N(2≤N≤1000)N \ (2 \leq N \leq 1000)N (2≤N≤1000), the number of points. The following NNN lines each contains two integers xi,yi(∣xi,yi∣≤1000)x_i, y_i \ (|x_i, y_i| \leq 1000)xi​,yi​ (∣xi​,yi​∣≤1000), denoting the x-coordinate and the y-coordinate of the i\ i i-th point.

It is guaranteed that the sum of N\ N N over all cases does not exceed 2×1052 \times 10^52×105 .

输出描述:

For each case, print four integers x1,y1,x2,y2x_1, y_1, x_2, y_2x1​,y1​,x2​,y2​​ in a line, representing a line passing through (x1,y1)(x_1, y_1)(x1​,y1​) and (x2,y2)(x_2, y_2)(x2​,y2​). Obviously the output must satisfy (x1,y1)≠(x2,y2)(x_1,y_1) \ne (x_2,y_2)(x1​,y1​)​=(x2​,y2​).
The absolute value of each coordinate must not exceed 10910^9109 . It is guaranteed that at least one solution exists. If there are multiple solutions, print any of them.

示例1

输入

1
4
0 1
-1 0
1 0
0 -1

输出

-1 999000000 1 -999000001

思维题~
我们对点按 xxx 为第一关键字,yyy 为第二关键字排序,只要把最中间的两个点错位输出即可,错位有个小技巧,我们假设找到的点为 p1p_1p1​ 和 p2p_2p2​,错位很简单,p1.x+1p_1.x+1p1​.x+1,然后 p2.x−1p_2.x-1p2​.x−1即可,此时我们能保证两个点的连线是能平分所有点的,但此时可能会过图中的点,怎么办呢,我们发现点的绝对值不过 1000,所以只要在加减一个大于1000的值就能避免和点重合的情况,AC代码如下:

#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
pair<int,int>p[1005];
int eps=1000;
main(){int n,t;scanf("%d",&t);while(t--){scanf("%d",&n);for(int i=0;i<n;i++) scanf("%d%d",&p[i].first,&p[i].second);sort(p,p+n);printf("%d %d %d %d\n",p[n/2-1].first+1,p[n/2-1].second-eps,p[n/2].first-1,p[n/2].second+eps);}
}

2019牛客暑期多校训练营(第三场)H.Magic Line相关推荐

  1. 2019牛客暑期多校训练营 第三场 I Median

    传送门 链接:https://ac.nowcoder.com/acm/contest/883/I 来源:牛客网 JSB has an integer sequence a1,a2,-,ana_1, a ...

  2. 【2019牛客暑期多校训练营(第二场) - H】Second Large Rectangle(单调栈,全1子矩阵变形)

    题干: 链接:https://ac.nowcoder.com/acm/contest/882/H 来源:牛客网 题目描述 Given a N×MN \times MN×M binary matrix. ...

  3. 2019牛客暑期多校训练营(第一场)E-ABBA(dp)

    链接:https://ac.nowcoder.com/acm/contest/881/E 来源:牛客网 时间限制:C/C++ 2秒,其他语言4秒 空间限制:C/C++ 524288K,其他语言1048 ...

  4. 2019牛客暑期多校训练营(第一场)

    传送门 参考资料: [1]:官方题解(提取码:t050 ) [2]:标程(提取码:rvxr ) [3]:牛客题解汇总 A.Equivalent Prefixes(单调栈) •题意 定义两个数组 u,v ...

  5. 2019牛客暑期多校训练营(第一场) A Equivalent Prefixes ( st 表 + 二分+分治)

    链接:https://ac.nowcoder.com/acm/contest/881/A 来源:牛客网 Equivalent Prefixes 时间限制:C/C++ 2秒,其他语言4秒 空间限制:C/ ...

  6. 【2019牛客暑期多校训练营(第二场)- E】MAZE(线段树优化dp,dp转矩阵乘法,线段树维护矩阵乘法)

    题干: 链接:https://ac.nowcoder.com/acm/contest/882/E?&headNav=acm 来源:牛客网 Given a maze with N rows an ...

  7. 【2019牛客暑期多校训练营(第二场)- F】Partition problem(dfs,均摊时间优化)

    题干: 链接:https://ac.nowcoder.com/acm/contest/882/F 来源:牛客网 Given 2N people, you need to assign each of ...

  8. 【2019牛客暑期多校训练营(第二场) - D】Kth Minimum Clique(bfs,tricks)

    题干: 链接:https://ac.nowcoder.com/acm/contest/882/D 来源:牛客网 Given a vertex-weighted graph with N vertice ...

  9. 【2019牛客暑期多校训练营(第一场) - A】Equivalent Prefixes(单调栈,tricks)

    题干: 链接:https://ac.nowcoder.com/acm/contest/881/A 来源:牛客网 Two arrays u and v each with m distinct elem ...

  10. 【2019牛客暑期多校训练营(第一场) - H】XOR(线性基,期望的线性性)

    题干: 链接:https://ac.nowcoder.com/acm/contest/881/H 来源:牛客网 Bobo has a set A of n integers a1,a2,-,ana1, ...

最新文章

  1. 2019 半导体领袖新年展望(一)| 半导体行业观察
  2. ubuntu自动登录tty1(shell,text)配置
  3. LAMP源码编译安装配置+wordpress
  4. 问题合集 ------- 用 Eclipse 平台进行 C/C++ 开发
  5. java郝斌_郝斌Java自学教程全集打包
  6. 容器编排技术 -- Kubernetes Replica Sets
  7. [USB-Blaster] Error (209040): Can't access JTAG chain
  8. jQuery AJAX实现调用页面后台方法
  9. 第二章 tcp/ip
  10. webpack5+vue3搭建h5项目模板-(二)-eslint代码规范化
  11. linux 设置显卡命令,linux查看显卡命令
  12. MXF 媒体交换文件格式
  13. 桌宠java_桌宠 下了Java还是说没法登上去 PHILIPS 电脑
  14. C++一步解决cls闪烁问题
  15. 问游戏java面试问题_JAVA程序员面试32问,你能回答多少题?
  16. Unity5.3官方VR教程重磅登场-系列6 VR真机测试和产品发布
  17. 笔记本Ubuntu系统关闭独显+省电降温设置
  18. Python爬虫豆瓣电影top250
  19. 华为nova8pro和小米11哪个好
  20. 修复setup violation的方法总结

热门文章

  1. 无root 修改/usr/lib/x86_64-linux-gnu/libstdc 解决ImportError: /usr/lib/x86_64-linux-gnu/libstdc++.so.6: v
  2. 【Halcon视觉】标定
  3. 请写一个关于低脂猴头菇牛肉酱加工工艺优化的论文框架
  4. 《云云众声》第97期:关于云计算 不可不说的大事小情
  5. 什么蓝牙耳机玩游戏没有延时?适合玩游戏的蓝牙耳机推荐
  6. 文化衫工作服职业装设计公司网站模板
  7. 用电脑怎么知道对方的ip地址
  8. MQL5教程6 K线数据相关
  9. NATAPP 购买隧道的优惠码,免费拿走不谢
  10. python常用命令参考手册_Python基础#常用命令和函数