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 ...
随机推荐
- Angular JS 中 ng-controller 值复制和引用复制
我们知道在使用ng-app或者ng-controller指令的时候,都会创建一个新的作用域($rootScope或者是$scope),并且在使用ng-controller指令创建的作用域会继承父级作用 ...
- Mybatis连接查询返回类型问题
一对一映射 public class Card { private Integer id; private String num; private Student student; //重要 publ ...
- redis订阅者与发布者
#conding=utf-8 #一.创建redis类 文件名 RedisHelper import redis # conn=redis.Redis(host='127.0.0.1')# import ...
- 关于STM32GPIO按键上下拉配置的认识
说真的,后知后觉这个问题还是有点值得研究的,一开始学习我用的板子在按键模块电路中GPIO输入脚是有外部上下拉电阻的,如下图所示:当KEY1接V3.3,在其后为它接一个下拉电阻,可以保证按下按键输入高电 ...
- 4、一个打了鸡血的for循环(增强型for循环)
对于循环,我们大家应该都不陌生,例如do-while循环,while循环,for循环,今天给大家介绍一个有趣的东西——打了鸡血的for循环(增强型for循环). 首先看代码,了解一下for循环的结构: ...
- leetcode 29 两数相除
问题描述 给定两个整数,被除数 dividend 和除数 divisor.将两数相除,要求不使用乘法.除法和 mod 运算符. 返回被除数 dividend 除以除数 divisor 得到的商. 示例 ...
- android ——Intent
Intent是android程序中各组件之间进行交互的重要方式,它可以用于指明当前组件想要执行的动作,也可以在不同组件之间传递数据,Intent一般被用于启动活动,启动服务以及发送广播. 一.显式的使 ...
- (三十一)c#Winform自定义控件-文本框(四)
前提 入行已经7,8年了,一直想做一套漂亮点的自定义控件,于是就有了本系列文章. 开源地址:https://gitee.com/kwwwvagaa/net_winform_custom_control ...
- 普通Apache的安装与卸载
Apache安装与卸载ctrl+F快捷查找 1.下载apache 64位解压 官网:http://httpd.apache.org/ 文件使用记事本或者sublime2.修改 打开apache目录下的 ...
- js设置,取得,清除cookie
//取得cookie function getCookie(name) { var nameEQ = name + "="; var ca = document.cookie. ...