zoukankan      html  css  js  c++  java
  • 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
    ", p[1].x, p[1].y, a, b);
        }
    }
    
  • 相关阅读:
    ROS系统MoveIt玩转双臂机器人系列(六)--D-H逆运动学求解程序(C++)
    ROS系统MoveIt玩转双臂机器人系列(五)--浅议机器人运动学与D-H建模
    ROS系统MoveIt玩转双臂机器人系列(四)--用户接口的使用
    ROS系统MoveIt玩转双臂机器人系列(三)--利用controller控制实际机器人
    ROS系统MoveIt玩转双臂机器人系列(二)--生成MoveIt配置包
    总纲篇:产品结构设计指导VII(本博客指引章节)
    高阶篇:1)概念设计-总章
    进阶篇:3.3)DFM-铸造件设计总章
    进阶篇:3.4.3)DFM钻削件设计指南
    进阶篇:3.4.4)DFM铣削件设计指南
  • 原文地址:https://www.cnblogs.com/bpdwn-cnblogs/p/11247943.html
Copyright © 2011-2022 走看看