zoukankan      html  css  js  c++  java
  • Ural_1207. Median on the Plane(计算几何)

      /*思路完全搞乱,开始就没想清楚就写。我晕,各种WA。

    思路:

      找到所有点中最下边一层点里边最靠左的点d。然后求d到其他每个点连线与x轴的
    夹角Θ(0 <= Θ <= π 因为d的纵坐标最小)。然后从小到大排序,找到存角度的数组
    里n/2号点就是要找的另一个点。
    */

    My Code:

    #include <iostream>
    #include <cstdio>
    #include <cstring>
    #include <algorithm>
    #include <cmath>
    #define pi 3.1415926535

    using namespace std;

    const int N = 10010;

    struct point{
    double x;
    double y;
    }p[N];

    struct angle{
    double ang;
    int i;
    }a[N];

    point tmp;

    bool cmp(angle a, angle b){
    return a.ang < b.ang;
    }
    int main(){
    //freopen("data.in", "r", stdin);

    int n, i, d, j;
    double b, c;

    scanf("%d", &n);
    scanf("%lf%lf", &p[1].x, &p[1].y);
    b = p[1].x; c = p[1].y; d = 1;

    for(i = 2; i <= n; i++){
    scanf("%lf%lf", &p[i].x, &p[i].y);
    if(c > p[i].y){
    b = p[i].x; c = p[i].y; d = i;
    }
    if(c == p[i].y && b > p[i].x){
    b = p[i].x; c = p[i].y; d = i;
    }
    }

    for(j = 1, i = 1; i <= n; i++){
    if(i != d){
    a[j].i = i;
    b = p[i].x - p[d].x;
    c = p[i].y - p[d].y;
    if(b == 0) {a[j++].ang = pi/2; continue;}
    if(c == 0) {a[j++].ang = 0; continue;}
    if(p[i].x < p[d].x)
    a[j++].ang = pi - atan(c/b);
    else
    a[j++].ang = atan(c/b);
    }
    }
    sort(a+1, a+n, cmp);
    /*for(i = 1; i < n; i++){
    printf("%lf %d\n", a[i].ang, a[i].i);
    }
    */
    printf("%d %d\n", d, a[n/2].i);
    return 0;
    }
  • 相关阅读:
    k8s存储(部署理论)
    DELL R720针对磁盘故障面板信息误报解决
    ovirt平台新建kvm操作
    宿主机计划任务执行docker相关命令
    网企-11-12
    洛谷-P1164 小A点菜
    洛谷-P1060 开心的金明
    洛谷-P1305 新二叉树
    洛谷-P1030 求先序排列
    洛谷-P1087 FBI树
  • 原文地址:https://www.cnblogs.com/vongang/p/2228096.html
Copyright © 2011-2022 走看看