题目连接:

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);
}
}

H-Magic Line_2019 牛客暑期多校训练营(第三场)的更多相关文章

  1. 2019牛客暑期多校训练营(第三场)H题目

    题意:给你一个N×N的矩阵,求最大的子矩阵 满足子矩阵中最大值和最小值之差小于等于m. 思路:这题是求满足条件的最大子矩阵,毫无疑问要遍历所有矩阵,并判断矩阵是某满足这个条件,那么我们大致只要解决两个 ...

  2. 2019牛客暑期多校训练营(第三场) F.Planting Trees(单调队列)

    题意:给你一个n*n的高度矩阵 要你找到里面最大的矩阵且最大的高度差不能超过m 思路:我们首先枚举上下右边界,然后我们可以用单调队列维护一个最左的边界 然后计算最大值 时间复杂度为O(n*n*n) # ...

  3. 2019牛客暑期多校训练营(第三场)- F Planting Trees

    题目链接:https://ac.nowcoder.com/acm/contest/883/F 题意:给定n×n的矩阵,求最大子矩阵使得子矩阵中最大值和最小值的差值<=M. 思路:先看数据大小,注 ...

  4. 2019牛客暑期多校训练营(第九场)A:Power of Fibonacci(斐波拉契幂次和)

    题意:求Σfi^m%p. zoj上p是1e9+7,牛客是1e9:  对于这两个,分别有不同的做法. 前者利用公式,公式里面有sqrt(5),我们只需要二次剩余求即可.     后者mod=1e9,5才 ...

  5. 2019牛客暑期多校训练营(第一场)A题【单调栈】(补题)

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

  6. 2019牛客暑期多校训练营(第二场)F.Partition problem

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

  7. [状态压缩,折半搜索] 2019牛客暑期多校训练营(第九场)Knapsack Cryptosystem

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

  8. 2019牛客暑期多校训练营(第一场) B Integration (数学)

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

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

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

  10. 2019牛客暑期多校训练营(第一场)A Equivalent Prefixes(单调栈/二分+分治)

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

随机推荐

  1. python3 导入包总提示no moudle named xxx

    一.python中的包有三种 1.python自带的包,如sys, os 2.python的第三方库,如 requests, selenium 3.自己写的.py文件 二.今天主要说下导入自己写的包 ...

  2. python传递参数

    1.脚本 # -*- coding: utf-8 -*- from sys import argvscript, first,second = argv #将命令中输入的参数解包后传递给左边 age ...

  3. java连接oracle数据库jdbc

    driver = oracle.jdbc.driver.OracleDriver url = jdbc:oracle:thin:@localhost:1521:orcl

  4. 【Java】设置 JPanel 宽度

    panel.setSize(200, 300); //该方法无效 panel.setPreferredSize(new Dimension(800, 0)); //使用该方法 参考链接: http:/ ...

  5. 在ABP中灵活使用AutoMapper

    demo地址:ABP.WindowsService 该文章是系列文章 基于.NetCore和ABP框架如何让Windows服务执行Quartz定时作业 的其中一篇. AutoMapper简介 Auto ...

  6. 有助于提高"锁"性能的几点建议

    有助于提高"锁"性能的几点建议 1.减少锁持有时间 public synchronized void syncMethod() { othercode1(); mutextMeth ...

  7. 浅谈 ASCII、Unicode、UTF-8,一目了然

    对于ASCII.Unicode.UTF-8这三种编码方式我们经常用到,也经常挂到嘴边,但他们是怎么来的,为什么要存在,具体是怎么个规则,我们并没有做深入了解,下面,就带你看一下他们到底是怎么回事吧…… ...

  8. JavaFx应用 星之小说下载器

    星之小说下载器 说明: 需要jdk环境 目前只支持铅笔小说网,后续添加更多书源,还有安卓版,敬请期待. 喜欢的话,不妨打赏一波! 软件交流QQ群:690380139 断点下载暂未实现,小说下载途中,一 ...

  9. python基础--列表,元组

    list1 = [1,2,3,4,5,6]list2 = ['wang','cong']# 1对列表中的元素取值(通过索引)print(list1[3]) # 4print(list2[1]) # c ...

  10. Nunit与Xunit介绍

    Nunit安装 首先说下,nunit2.X与3.X版本需要安装不同的vs扩展. nunit2.x安装 安装如上3个,辅助创建nunit测试项目与在vs中运行单元测试用例 . 1.Nunit2 Test ...