Submission #80442


ソースコード

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
#include<bits/stdc++.h>
using namespace std;
#define int long long
struct Point
{
int x, y;
Point(int x, int y) : x(x), y(y)
{
};
Point()
{
};
Point operator+(const Point& a) const
{
return (Point(x + a.x, y + a.y));
}
Point operator-(const Point& a) const
{
return (Point(x - a.x, y - a.y));
}
bool operator<(const Point& b) const
{
return x != b.x ? x < b.x : y < b.y;
}
double abs()
{
return (sqrt(x * x + y * y));
}
};
double cross(const Point& a, const Point& b)
{
return a.x * b.y - a.y * b.x;
}
/*
ポイント型で二次元の点の座標をvectorに入れて与える
返り値:凸包に含まれる頂点の頂点番号
*/
vector< int > Convex_Hull(vector< Point > p)
{
int n = p.size(), k = 0;
vector< int > order(p.size());
for(int i = 0; i < n; i++) order[i] = i;
sort(begin(order), end(order), [&](int a, int b)
{
return (p[a] < p[b]);
});
vector< int > ch(2 * n);
for(int i = 0; i < n; ch[k++] = order[i++]) {
while(k >= 2 && cross(p[ch[k - 1]] - p[ch[k - 2]], p[order[i]] - p[ch[k - 1]]) < 0) --k;
}
for(int i = n - 2, t = k + 1; i >= 0; ch[k++] = order[i--]) {
while(k >= t && cross(p[ch[k - 1]] - p[ch[k - 2]], p[order[i]] - p[ch[k - 1]]) < 0) --k;
}
ch.resize(k - 1);
return (ch);
}
double f(double ax,double ay,double bx,double by,double cx,double cy){
double a=sqrt((ax-bx)*(ax-bx)+(ay-by)*(ay-by));
double b=sqrt((cx-bx)*(cx-bx)+(cy-by)*(cy-by));
double c=sqrt((cx-ax)*(cx-ax)+(cy-ay)*(cy-ay));
double s=(a+b+c)/2;
return sqrt(s*(s-a)*(s-b)*(s-c));
}
signed main(){
int n;cin>>n;
vector<Point>a(n);
vector<int>b;
for(int i=0;i<n;i++){
cin>>a[i].x>>a[i].y;
}
b = Convex_Hull(a);
double ans=0;
for(int i=1;i<b.size()-1;i++){
ans+=f(a[b[0]].x , a[b[0]].y , a[b[i]].x , a[b[i]].y , a[b[i+1]].x , a[b[i+1]].y );
//cout<<f(a[b[0]].x , a[b[0]].y , a[b[i]].x , a[b[i]].y , a[b[i+1]].x , a[b[i+1]].y )<<" ["<<b[0]<<" : "<<b[i]<<" : "<<b[i+1]<<"]\n";
}
printf("%.10lf\n",ans);
}

ステータス

項目 データ
問題 1841 - PCKに出そうな幾何練習
ユーザー名 ei2326
投稿日時 2024-08-21 11:03:56
言語 C++17
状態 Accepted
得点 1
ソースコード長 2181 Byte
最大実行時間 27 ms
最大メモリ使用量 668 KB

セット

セット 得点 Cases
1 ALL 1 / 1 *

テストケース

ファイル名 状態 実行時間 メモリ使用量 #
in1.txt AC 23 ms 604 KB
1
in2.txt AC 27 ms 580 KB
1
in3.txt AC 24 ms 668 KB
1
in4.txt AC 18 ms 508 KB
1
in5.txt AC 20 ms 352 KB
1
in6.txt AC 20 ms 448 KB
1