【无标题】

[HBCPC2024] Nana Likes Polygons

[HBCPC2024] Nana Likes Polygons

题目描述

Nana’s electronic pet, MACARON, enjoys moving around in the room. Nana wants to create a boundedarea where MACARON can roam within.

The positions in the room can be represented using a two-dimensional coordinate system, and Nana provides a set of vertices on it. Nana likes polygons and now wants to select a subset of vertices that can form a convex polygon as its endpoints. However, Nana also wants to ensure that the selected area is not too big.

Thus, she is going to determine the minimum possible area of the convex polygon ending on a subset of given vertices. If such a convex polygon doesn’t exist, please output -1 (without quotes).

输入格式

The first line contains a single integer T ( 1 ≤ T ≤ 10 ) T (1 \leq T \leq 10) T(1T10) — the number of test cases.

For each test case, the first line contains a single integer n ( 1 ≤ n ≤ 100 ) n (1 \leq n \leq 100) n(1n100) — the number of given vertices.

The following n n n lines each contain two integers, and the i i i-th line contains x i , y i ( − 1000 ≤ x i , y i ≤ 1000 ) x_i, y_i (-1000 \leq x_i, y_i \leq 1000) xi,yi(1000xi,yi1000) — the coordinate of the i i i-th vertex.

输出格式

For each test case, if no such convex polygon, please output -1 without quotes; otherwise output a single real number denoting the minimum possible area of the convex polygon ending on these given vertices.

Let a a a and b b b denote the answer and your output respectively. Your output will be accepted if the absolute or relative error of b b b does not exceed 1 0 − 6 10^{-6} 106. Formally, your output is accepted if and only if ∣ a − b ∣ max ⁡ ( a , b ) ≤ 1 0 − 6 \dfrac{|a-b|}{\max(a,b)} \leq 10^{-6} max(a,b)ab106

样例 #1

样例输入 #1

2
4
0 -1
-3 0
0 2
2 2
3
-1 -1
0 0
1 1

样例输出 #1

2
-1

提示

For the first test case, choose ( 2 , 2 ) , ( − 3 , 0 ) (2, 2), (−3, 0) (2,2),(3,0), and ( 0 , 2 ) (0, 2) (0,2) as endpoints of a convex polygon with area 2 2 2. It can be proved that this is the minimized area in this case.

For the second test case, no convex polygon can be formed by these three vertices.

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

double dis(double sx, double sy, double tx, double ty) {
    return sqrt((tx - sx) * (tx - sx) + (ty - sy) * (ty - sy));
}

double S(double a, double b, double c) {
    double s = (a + b + c) / 2.0;
    return sqrt(s * (s - a) * (s - b) * (s - c));
}

pair<double, double> a[1000];

int main() {
    int t;
    cin >> t;
    while (t--) {
        int n;
        cin >> n;
        bool flag = false;
        
        for (int i = 0; i < n; i++) {
            cin >> a[i].first >> a[i].second;
        }
        
        double min1 = 1e18;
        for (int i = 0; i < n; i++) {
            for (int j = i + 1; j < n; j++) {
                for (int k = j + 1; k < n; k++) {
                    double x1 = a[i].first;
                    double y1 = a[i].second;
                    double x2 = a[j].first;
                    double y2 = a[j].second;
                    double x3 = a[k].first;
                    double y3 = a[k].second;
                    
                    double u = dis(x1, y1, x2, y2);
                    double v = dis(x1, y1, x3, y3);
                    double w = dis(x2, y2, x3, y3);
                    double s = S(u, v, w);
                    
                    if (s > 0.0) {
                        min1 = min(min1, s);
                        flag = true;
                    }
                }
            }
        }
        if (flag) {
            printf("%.8Lf\n", min1);
        } else {
            cout << "-1" << endl;
        }
    }
    return 0;
}

  • 13
    点赞
  • 11
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值