H-Magic Line_2019 牛客暑期多校训练营(第三场)
题目连接:
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 牛客暑期多校训练营(第三场)的更多相关文章
- 2019牛客暑期多校训练营(第三场)H题目
题意:给你一个N×N的矩阵,求最大的子矩阵 满足子矩阵中最大值和最小值之差小于等于m. 思路:这题是求满足条件的最大子矩阵,毫无疑问要遍历所有矩阵,并判断矩阵是某满足这个条件,那么我们大致只要解决两个 ...
- 2019牛客暑期多校训练营(第三场) F.Planting Trees(单调队列)
题意:给你一个n*n的高度矩阵 要你找到里面最大的矩阵且最大的高度差不能超过m 思路:我们首先枚举上下右边界,然后我们可以用单调队列维护一个最左的边界 然后计算最大值 时间复杂度为O(n*n*n) # ...
- 2019牛客暑期多校训练营(第三场)- F Planting Trees
题目链接:https://ac.nowcoder.com/acm/contest/883/F 题意:给定n×n的矩阵,求最大子矩阵使得子矩阵中最大值和最小值的差值<=M. 思路:先看数据大小,注 ...
- 2019牛客暑期多校训练营(第九场)A:Power of Fibonacci(斐波拉契幂次和)
题意:求Σfi^m%p. zoj上p是1e9+7,牛客是1e9: 对于这两个,分别有不同的做法. 前者利用公式,公式里面有sqrt(5),我们只需要二次剩余求即可. 后者mod=1e9,5才 ...
- 2019牛客暑期多校训练营(第一场)A题【单调栈】(补题)
链接:https://ac.nowcoder.com/acm/contest/881/A来源:牛客网 题目描述 Two arrays u and v each with m distinct elem ...
- 2019牛客暑期多校训练营(第二场)F.Partition problem
链接:https://ac.nowcoder.com/acm/contest/882/F来源:牛客网 Given 2N people, you need to assign each of them ...
- [状态压缩,折半搜索] 2019牛客暑期多校训练营(第九场)Knapsack Cryptosystem
链接:https://ac.nowcoder.com/acm/contest/889/D来源:牛客网 时间限制:C/C++ 2秒,其他语言4秒 空间限制:C/C++ 262144K,其他语言52428 ...
- 2019牛客暑期多校训练营(第一场) B Integration (数学)
链接:https://ac.nowcoder.com/acm/contest/881/B 来源:牛客网 Integration 时间限制:C/C++ 2秒,其他语言4秒 空间限制:C/C++ 5242 ...
- 2019牛客暑期多校训练营(第一场) A Equivalent Prefixes ( st 表 + 二分+分治)
链接:https://ac.nowcoder.com/acm/contest/881/A 来源:牛客网 Equivalent Prefixes 时间限制:C/C++ 2秒,其他语言4秒 空间限制:C/ ...
- 2019牛客暑期多校训练营(第一场)A Equivalent Prefixes(单调栈/二分+分治)
链接:https://ac.nowcoder.com/acm/contest/881/A来源:牛客网 Two arrays u and v each with m distinct elements ...
随机推荐
- Android Studio 'AIDL is missing' 且 不识别R文件
最近刚开始用Android Studio,出的问题还真不少.昨天不知为何不能新建项目了,这两天重装了几次才搞定. 可又出了这个问题: 原因:Compile Sdk Version和Build Tool ...
- Selenium+java - 下拉框处理
常见下拉框也分两种:一种是标准控件和非标准控件(一般为前端开发人员自己封装的下拉框),本篇文章中将重点讲解标准下拉框操作. 1.Select提供了三种选择某一项的方法 select.selectByI ...
- 基于TP5.1实用案例及教程
推荐<基于TP5.1实用案例及教程>书 目录: 通用封装 Export通用封装Import通用封装配合Import通用封装的ImportBaseVerify类Files通用封装Direct ...
- Js面向对象原型~构造函数
脑袋一团浆糊,但希望写点啥,所有就有了这篇博文了,抱歉哦....开始吧!!!! 什么是构造函数?? 所谓"构造函数",其实就是一个普通函数,但是内部使用了this变量.对构造 ...
- ajax具体实现学习记录
记录自己对ajax\的理解, 首先要明白ajax是为了解决什么问题,简单来讲就是为了局部刷新页面,而不刷新整个界面.就比如现在有一个实时热度的显示,它是不断变化的,所以你肯定要不停的从数据库当中获取热 ...
- 【Java例题】3.1 7、11、13的倍数
1.找出1~5000范围内分别满足如下条件的数: (1) 7或11或13的倍数 (2) 7.11,或7.13或11.13的倍数 (3) 7.11和13的倍数. package chapter3; pu ...
- 使用ArrayPool池化大型数组(翻译)
原文链接:https://adamsitnik.com/Array-Pool/ 使用ArrayPool 简介 .NET的垃圾收集器(GC)实现了许多性能优化,其中之一就是,设定年轻的对象很快消亡,然而 ...
- 简述关于ASP.NET MVC与.NET CORE 的区别
简述关于ASP.NET MVC与.NET CORE的区别1.关于ASP.NET 关于MVC刚开始接触这个技术的时候我经常不理解他们的名字,我相信许多学ASP.NET开发人员开始接触MVC应该也和我一样 ...
- spring boot 打 war包
spring boot .spring cloud打 war包,并发布到tomcat中运行 1.pom文件修改 <packaging>war</packaging> 2.< ...
- 昂贵的聘礼 POJ - 1062
题目链接:https://vjudge.net/problem/POJ-1062 如图,我们可以把交换的情况,抽象为一个有向图, 先抛去等级限制,那么就是一个最短路,从①出发,到达其他点的最短路中 最 ...