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
89
| // 더 많은 정보는 42jerrykim.github.io 에서 확인하세요.
#include <bits/stdc++.h>
using namespace std;
struct Point { long double x, y; };
static inline Point operator+(const Point& a, const Point& b){ return {a.x+b.x, a.y+b.y}; }
static inline Point operator-(const Point& a, const Point& b){ return {a.x-b.x, a.y-b.y}; }
static inline Point operator*(const Point& a, long double k){ return {a.x*k, a.y*k}; }
static inline long double cross(const Point& a, const Point& b){ return a.x*b.y - a.y*b.x; }
static inline long double dist(const Point& a, const Point& b){ long double dx=a.x-b.x, dy=a.y-b.y; return sqrtl(dx*dx+dy*dy); }
int main(){
ios::sync_with_stdio(false);
cin.tie(nullptr);
int N; if(!(cin>>N)) return 0;
vector<Point> P(N);
for(int i=0;i<N;i++){ long long xi, yi; cin>>xi>>yi; P[i] = {(long double)xi, (long double)yi}; }
vector<long double> prefLen(N+1, 0.0L), prefCross(N+1, 0.0L);
for(int i=0;i<N;i++){
int j=(i+1==N?0:i+1);
prefLen[i+1] = prefLen[i] + dist(P[i], P[j]);
prefCross[i+1] = prefCross[i] + cross(P[i], P[j]);
}
long double L = prefLen[N];
long double halfL = L * 0.5L;
long double A = prefCross[N] * 0.5L;
auto locate = [&](long double s){
// s in [0, L)
int e = int(upper_bound(prefLen.begin(), prefLen.end(), s) - prefLen.begin()) - 1;
if(e < 0) e = 0; if(e >= N) e = N-1;
long double segStart = prefLen[e];
long double segLen = prefLen[e+1] - segStart;
long double alpha = (segLen>0 ? (s - segStart)/segLen : 0.0L);
if(alpha < 0) alpha = 0; if(alpha > 1) alpha = 1;
Point pt = P[e] + (P[(e+1==N?0:e+1)] - P[e]) * alpha;
return tuple<int,long double,Point>(e, alpha, pt);
};
auto area_s_to_t = [&](long double s, long double t){
if(t < s) t += L;
auto [es, fs, S] = locate(fmodl(s + L, L));
auto [et, ft, T] = locate(fmodl(t, L));
long double sumC = 0.0L;
int esn = (es+1==N?0:es+1);
sumC += cross(S, P[esn]);
long double middle = 0.0L;
if(t <= L){
if(et >= es+1) middle = prefCross[et] - prefCross[es+1];
} else {
middle = (prefCross[N] - prefCross[es+1]) + (prefCross[et] - prefCross[0]);
}
sumC += middle;
sumC += cross(P[et], T);
sumC += cross(T, S);
return sumC * 0.5L;
};
auto f = [&](long double s){ return area_s_to_t(s, s + halfL) - A * 0.5L; };
long double left = 0.0L, right = halfL;
long double fl = f(left), fr = f(right);
if(fabsl(fl) >= 1e-18L && fabsl(fr) >= 1e-18L){
for(int it=0; it<100; ++it){
long double mid = (left + right) * 0.5L;
long double fm = f(mid);
if((fl <= 0 && fm <= 0) || (fl >= 0 && fm >= 0)){ left = mid; fl = fm; }
else { right = mid; fr = fm; }
}
}
long double sStar = (left + right) * 0.5L;
long double tStar = sStar + halfL; if(tStar >= L) tStar -= L;
auto [js, alpha, Spt] = locate(sStar);
auto [kt, beta, Tpt] = locate(tStar);
if(alpha < 0) alpha = 0; if(alpha > 1) alpha = 1;
if(beta < 0) beta = 0; if(beta > 1) beta = 1;
cout.setf(std::ios::fixed); cout<<setprecision(12);
cout << "YES\n";
cout << (js+1) << ' ' << alpha << "\n";
cout << (kt+1) << ' ' << beta << "\n";
return 0;
}
|