题目连接:

https://ac.nowcoder.com/acm/contest/883/H

Description

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

ZYB got 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.

Input

There are multiple cases. The first line of the input contains a single integer \(T(1<=T<=1000)\), indicating the number of cases.

For each case, the first line of the input contains a single even integer \(N (2 <= N <= 1000)\), the number of points. The following \(N\) lines each contains two integers xi,yi |(xi,yi)| <= 1000, denoting the x-coordinate and the y-coordinate of the -th point.

It is guaranteed that the sum of N over all cases does not exceed 2*10^5.

Output

For each case, print four integers \(x_1, y_1, x_2, y_2\) in a line, representing a line passing through \((x_1, y_1)\) and$ (x_2, y_2)$. Obviously the output must satisfy .

The absolute value of each coordinate must not exceed \(10^9\). It is guaranteed that at least one solution exists. If there are multiple solutions, print any of them.

Sample Input

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

Sample Output

-1 999000000 1 -999000001

Hint

题意

二维平面上有n个整数坐标的点,求出一条直线将平面上的点分为数量相等的两部分,且线上不能有点,输出线上两个点确定该直线

题解:

先在左下角无穷远处取一质数坐标点(x,y) 对该点和n个点进行极角排序,设排序后中点坐标为(a,b)则这两点连线会将点分为数量相等的两部分,接着取左下角关于中点的对称点(a+a-x, b+b-y),再将该点左移动一格变成(2a-x-1, 2b-y)
则(x,y) (2a-x-1, 2b-y)两点确定的直线就可以分割点为两部分,且线上不会有点

代码

#include <cstdio>
#include <cmath>
#include <cstring>
#include <algorithm>
using namespace std;
const int MAX=100005;
const int INF=999999;
typedef long long ll;int n,top;
struct Node
{ll x,y;
}p[MAX],S[MAX];
ll Cross(Node a,Node b,Node c)
{return (b.x-a.x)*(c.y-a.y)-(b.y-a.y)*(c.x-a.x);
}ll dis(Node a,Node b)
{return (a.x-b.x)*(a.x-b.x)+(a.y-b.y)*(a.y-b.y);
}bool cmp(Node a,Node b)
{  ll flag = Cross(p[1],a,b);if(flag != 0) return flag > 0;return dis(p[1],a) < dis(p[1],b);
}int main()
{int T;scanf("%d", &T);while(T--){int n;scanf("%d", &n);p[1].x = -400000009; p[1].y = -2e3;for(int i=1;i<=n;i++)scanf("%lld%lld",&p[i+1].x,&p[i+1].y);n++;sort(p+2, p+1+n, cmp);int pos = n/2 + 1;ll a = p[pos].x - p[1].x + p[pos].x-1;ll b = p[pos].y - p[1].y + p[pos].y;printf("%lld %lld %lld %lld\n", p[1].x, p[1].y, a, b);}
}

转载于:https://www.cnblogs.com/bpdwn-cnblogs/p/11247943.html

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

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

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

  2. 2020牛客暑期多校训练营(第一场)

    文章目录 A B-Suffix Array B Infinite Tree C Domino D Quadratic Form E Counting Spanning Trees F Infinite ...

  3. 2020牛客暑期多校训练营(第二场)

    2020牛客暑期多校训练营(第二场) 最烦英语题 文章目录 A All with Pairs B Boundary C Cover the Tree D Duration E Exclusive OR ...

  4. E Groundhog Chasing Death(2020牛客暑期多校训练营(第九场))(思维+费马小定理+质因子分解)

    E Groundhog Chasing Death(2020牛客暑期多校训练营(第九场))(思维+费马小定理+质因子分解) 链接:https://ac.nowcoder.com/acm/contest ...

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

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

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

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

  7. 2019牛客暑期多校训练营(第九场)H Cutting Bamboos(主席树+二分)

    链接:https://ac.nowcoder.com/acm/contest/889/H 来源:牛客网 题目描述 There are n bamboos arranged in a line. The ...

  8. 2019牛客暑期多校训练营(第九场)A——The power of Fibonacci(循环节+中国剩余定理(互质)||广义BM)

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

  9. 2020牛客暑期多校训练营(第一场)A B-Suffix Array(后缀数组,思维)

    链接:https://ac.nowcoder.com/acm/contest/5666/A 来源:牛客网 题目描述 The BBB-function B(t1t2-tk)=b1b2-bkB(t_1 t ...

  10. 题解 | Popping Balloons-2019牛客暑期多校训练营第十场F题

    题目来源于牛客竞赛:https://ac.nowcoder.com/acm/contest/discuss 题目描述: 输入描述: 输出描述: 示例1: 示例2: 题解: 代码: #include&l ...

最新文章

  1. 解密jQuery事件核心 - 绑定设计(一)
  2. 两篇关于MCU的嵌入式应用的文章【ZZ】
  3. 类与接口(三)java中的接口与嵌套接口
  4. 使用Seq2Seq+attention实现简单的Chatbot
  5. k8s核心技术-Ingress(概述)---K8S_Google工作笔记0041
  6. Asp.net中模仿Winform的MessageBox
  7. [CareerCup] 12.6 Test an ATM 测试一个自动取款机
  8. ubuntu安装公式编辑器mathtype, wine中文乱码,ubuntu中文字体
  9. Chrome插件——一键保存网页为PDF1.0发布
  10. android修改shell串口号,[Note] 2021-01-15 Android shell/串口中使用 wpa_cli 连接Wi-Fi
  11. sed解析url的域名
  12. 关于高通8953开机需要按pwrkey很长时间的问题
  13. OV7725摄像头之OV7725芯片
  14. robo3T-操作MongoDB数据库常用命令
  15. 第二证券|钠电池三种技术路线谁更将率先取代锂电池?
  16. Android Studio使用技巧系列教程(四)
  17. python+django大学生专业社团信息管理系统
  18. 老调重弹之ffmpeg解码音频
  19. stats | 广义线性模型(三)——二元Logistic模型和Probit模型
  20. (附源码)计算机毕业设计ssm二手图书回收销售网站

热门文章

  1. spring-boot-maven-plugin多模块install问题解决办法
  2. 如何更好使用 ng-zorro-antd 图标
  3. 如何提高 Java 中锁的性能
  4. Java内嵌Groovy脚本引擎进行业务规则剥离(一)
  5. 魅族2016Java互联网方向其中一道笔试题--青蛙跳台阶问题
  6. 《梦断代码》读书笔记——第3、4、5章
  7. linux下find用法 find -name *.so -exec ll {} \;
  8. 蓝桥杯 ADV-149 算法提高 特殊的质数肋骨
  9. c#与马扎克通讯_马扎克伺服报警
  10. 获取对象的key_玩转 SpringBoot2.x 之缓存对象