首页 > 其他分享 >pta-神坛

pta-神坛

时间:2022-11-19 20:47:45浏览次数:28  
标签:node 神坛 return int s2 s1 pos pta

[神坛]pta

*相邻两条边围成的三角形面积会是最小的
极角排序+叉积计算三角形面积

#include<bits/stdc++.h>
#define int long long
using namespace std;

const int N = 2e5 + 10;
int n, m;
double ans = -1;
struct node{
    int x, y;
    int pos;
}a[N], b[N];

int jd(node s){
    if(s.x > 0 && s.y > 0) return 1;
    if(s.x < 0 && s.y > 0) return 2;
    if(s.x < 0 && s.y < 0) return 3;
    if(s.x > 0 && s.y < 0) return 4;
    return 0;//不加的话,vscode会报错
}

//计算几何:极角排序
bool cmp(node s1, node s2){
    if(s1.pos != s2.pos) return s1.pos < s2.pos;
    return s1.x * s2.y - s1.y * s2.x > 0;
}

signed main(){
    // ios::sync_with_stdio(false);
    // cin.tie(0); cout.tie(0);
    cin >> n;
    for(int i = 1; i <= n; i++) cin >> a[i].x >> a[i].y;
    for(int i = 1; i <= n; i++){
        int cnt = 0;
        for(int j = 1; j <= n; j++){//确定第二个点
            if(i == j) continue;
            b[++cnt].x = a[i].x - a[j].x;
            b[cnt].y = a[i].y - a[j].y;
            b[cnt].pos = jd(b[cnt]);
        }
        sort(b + 1, b + n, cmp);
        for(int j = 1; j < n - 1; j ++){
            if(ans == -1 || abs(b[j].x * b[j + 1].y - b[j].y * b[j + 1].x ) * 0.5 < ans){
                //叉乘计算三角形面积
                ans = abs(b[j].x * b[j + 1].y - b[j].y * b[j + 1].x ) * 0.5;
            }
        }
    }
    printf("%.3lf", ans);
    return 0;
}

标签:node,神坛,return,int,s2,s1,pos,pta
From: https://www.cnblogs.com/N-lim/p/16906963.html

相关文章

  • python第五章pta习题总结
    四、编程部分1、sorted函数:sorted(iterable,cmp=None,key=None,reverse=False)#iterable:可迭代的对象#cmp:比较规则#key:用来进行比较的对象,只有一个参数2、eval()......
  • iptables学习:MASQUERADE
    MASQUERADE,地址伪装,算是snat中的一种特例,可以实现自动化的snat。在iptables中有着和SNAT相近的效果,但也有一些区别,但使用SNAT的时候,出口ip的地址范围可以是一个,也可以是多......
  • Redirecting to /bin/systemctl stop iptables.service Failed to stop iptables.serv
    转载自:https://blog.csdn.net/buluxianfeng/article/details/108128520 ================= 一、问题描述在linux系统(centOS7)下安装mysql后,发现因防火墙问题连接不上......
  • CentOS 7 开启 iptables
    1、关闭CentOS7自带的 firewall防火墙#关闭防火墙systemctlstopfirewalld#取消开机启动systemctldisablefirewalld2、安装 iptables-services#Cetnos7默认已......
  • PTA_Maximum Subsequence Sum
    Givenasequenceof K integers{ N1​, N2​,..., NK​ }.Acontinuoussubsequenceisdefinedtobe{ Ni​, Ni+1​,..., Nj​ }where 1≤i≤j≤K.......
  • RHEL8 使用iptables-save无法保存防火墙规则
    环境RHEL8原因使用iptables-save命令执行后,无法保存iptables防火墙的规则,在下次重启系统后,会导致防火墙的规则链给重置到默认的规则链。解决使用maniptables-save查......
  • PTA一元多项式的乘法与加法运算
    设计函数分别求两个一元多项式的乘积与和。输入格式:输入分2行,每行分别先给出多项式非零项的个数,再以指数递降方式输入一个多项式非零项系数和指数(绝对值均为不超过1000......
  • PTA 数据结构 二分查找
    本题要求实现二分查找算法。函数接口定义: PositionBinarySearch(ListL,ElementTypeX); 其中List结构定义如下: typedefintPosition;typedefstructLNo......
  • PTA 21级数据结构与算法实验4—图论
    目录目录7-1邻接矩阵表示法创建无向图7-2邻接表创建无向图7-3图深度优先遍历7-4单源最短路径7-5列出连通集7-6哈利·波特的考试7-12关键活动7-13任务调度的合理性7......
  • ubuntu的iptables开机自动加载规则文件
    1、写一些规则sudoiptables-AINPUT-ptcp--dport80-jACCEPTsudoiptables-IINPUT-ptcp--dport3306-jREJECT2、保存到/etc/iptables.rules文件中sudo......