#include <bits/stdc++.h>
using namespace std;
typedef long long lint;
typedef long double llf;
typedef pair<int, int> pi;
struct pnt{
int first, second, idx;
};
lint ccw(pi a, pi b, pi c){
int dx1 = b.first - a.first;
int dy1 = b.second - a.second;
int dx2 = c.first - a.first;
int dy2 = c.second - a.second;
return 1ll * dx1 * dy2 - 1ll * dy1 * dx2;
}
lint ccw(pnt a, pnt b, pnt c){
int dx1 = b.first - a.first;
int dy1 = b.second - a.second;
int dx2 = c.first - a.first;
int dy2 = c.second - a.second;
return 1ll * dx1 * dy2 - 1ll * dy1 * dx2;
}
lint dist(pnt a, pnt b){
int dx = b.first - a.first;
int dy = b.second - a.second;
return 1ll * dx * dx + 1ll * dy * dy;
}
int n, m;
pi a[100005], b[100005];
void getch(vector<pnt> &v){
swap(v[0], *min_element(v.begin(), v.end(), [&](const pnt &a, const pnt &b){
return pi(a.first, a.second) < pi(b.first, b.second);
}));
sort(v.begin() + 1, v.end(), [&](const pnt &a, const pnt &b){
lint k = ccw(v[0], a, b);
if(k != 0) return k > 0;
return dist(v[0], a) < dist(v[0], b);
});
vector<pnt> h;
for(auto &i : v){
while(h.size() >= 2 && ccw(h[h.size() - 2], h.back(), i) <= 0){
h.pop_back();
}
h.push_back(i);
}
v = h;
}
int main(){
scanf("%d",&n);
for(int i=0; i<n; i++) scanf("%d %d",&a[i].first,&a[i].second);
scanf("%d",&m);
for(int i=0; i<m; i++) scanf("%d %d",&b[i].first,&b[i].second);
int lp = 0, rp = 0;
for(int i=1; i<m; i++){
if(ccw(a[0], b[lp], b[i]) < 0) lp = i;
if(ccw(a[0], b[rp], b[i]) > 0) rp = i;
}
vector<pnt> lv, rv;
vector<pi> mv;
for(int i=1; i<n; i++){
if(ccw(a[0], b[lp], a[i]) <= 0){
lv.push_back({a[i].first, a[i].second, -1});
}
if(ccw(a[0], b[rp], a[i]) >= 0){
rv.push_back({a[i].first, a[i].second, -1});
}
if(ccw(a[0], b[lp], a[i]) > 0 && ccw(a[0], b[rp], a[i]) < 0 && ccw(b[lp], b[rp], a[i]) <= 0){
mv.push_back(a[i]);
}
}
for(int i=0; i<m; i++){
lv.push_back({b[i].first, b[i].second, i});
rv.push_back({b[i].first, b[i].second, i});
}
getch(lv);
getch(rv);
int ps = -1, pe = -1;
pi ls, rs;
for(int i=0; i<lv.size(); i++){
if(lv[i].idx == -1 && lv[(i+1)%lv.size()].idx != -1){
ls = pi(lv[i].first, lv[i].second);
ps = lv[(i+1)%lv.size()].idx;
}
}
for(int i=0; i<rv.size(); i++){
if(rv[(i+1)%rv.size()].idx == -1 && rv[i].idx != -1){
rs = pi(rv[(i+1)%rv.size()].first, rv[(i+1)%rv.size()].second);
pe = rv[i].idx;
}
}
int ans = 0;
for(auto &i : mv){
bool okps = (ps == -1);
bool okpe = (pe == -1);
if(!okpe && ccw(a[0], b[pe], i) < 0 && ccw(rs, b[pe], i) < 0) okpe = 1;
if(!okps && ccw(a[0], b[ps], i) > 0 && ccw(ls, b[ps], i) > 0) okps = 1;
if(okps && okpe) ans++;
}
cout << n - ans - 1;
}
Compilation message
relay.cpp: In function 'int main()':
relay.cpp:87:16: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
for(int i=0; i<lv.size(); i++){
^
relay.cpp:93:16: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
for(int i=0; i<rv.size(); i++){
^
relay.cpp:57:16: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
scanf("%d",&n);
^
relay.cpp:58:64: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
for(int i=0; i<n; i++) scanf("%d %d",&a[i].first,&a[i].second);
^
relay.cpp:59:16: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
scanf("%d",&m);
^
relay.cpp:60:64: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
for(int i=0; i<m; i++) scanf("%d %d",&b[i].first,&b[i].second);
^
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
3584 KB |
Output is correct |
2 |
Correct |
0 ms |
3584 KB |
Output is correct |
3 |
Correct |
0 ms |
3584 KB |
Output is correct |
4 |
Correct |
0 ms |
3584 KB |
Output is correct |
5 |
Correct |
0 ms |
3584 KB |
Output is correct |
6 |
Correct |
0 ms |
3584 KB |
Output is correct |
7 |
Correct |
0 ms |
3584 KB |
Output is correct |
8 |
Correct |
0 ms |
3584 KB |
Output is correct |
9 |
Correct |
0 ms |
3584 KB |
Output is correct |
10 |
Correct |
0 ms |
3584 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
3584 KB |
Output is correct |
2 |
Correct |
0 ms |
3584 KB |
Output is correct |
3 |
Correct |
0 ms |
3584 KB |
Output is correct |
4 |
Correct |
0 ms |
3584 KB |
Output is correct |
5 |
Correct |
0 ms |
3584 KB |
Output is correct |
6 |
Correct |
0 ms |
3584 KB |
Output is correct |
7 |
Correct |
0 ms |
3584 KB |
Output is correct |
8 |
Correct |
0 ms |
3584 KB |
Output is correct |
9 |
Correct |
0 ms |
3584 KB |
Output is correct |
10 |
Correct |
0 ms |
3584 KB |
Output is correct |
11 |
Correct |
3 ms |
3900 KB |
Output is correct |
12 |
Correct |
3 ms |
3896 KB |
Output is correct |
13 |
Correct |
0 ms |
3732 KB |
Output is correct |
14 |
Correct |
0 ms |
3736 KB |
Output is correct |
15 |
Correct |
0 ms |
3724 KB |
Output is correct |
16 |
Correct |
0 ms |
3724 KB |
Output is correct |
17 |
Correct |
0 ms |
3732 KB |
Output is correct |
18 |
Correct |
3 ms |
3724 KB |
Output is correct |
19 |
Correct |
0 ms |
3724 KB |
Output is correct |
20 |
Correct |
0 ms |
3724 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
3584 KB |
Output is correct |
2 |
Correct |
0 ms |
3584 KB |
Output is correct |
3 |
Correct |
0 ms |
3584 KB |
Output is correct |
4 |
Correct |
0 ms |
3584 KB |
Output is correct |
5 |
Correct |
0 ms |
3584 KB |
Output is correct |
6 |
Correct |
0 ms |
3584 KB |
Output is correct |
7 |
Correct |
0 ms |
3584 KB |
Output is correct |
8 |
Correct |
0 ms |
3584 KB |
Output is correct |
9 |
Correct |
0 ms |
3584 KB |
Output is correct |
10 |
Correct |
0 ms |
3584 KB |
Output is correct |
11 |
Correct |
36 ms |
5460 KB |
Output is correct |
12 |
Correct |
29 ms |
5460 KB |
Output is correct |
13 |
Correct |
36 ms |
5460 KB |
Output is correct |
14 |
Correct |
33 ms |
5460 KB |
Output is correct |
15 |
Correct |
39 ms |
5588 KB |
Output is correct |
16 |
Correct |
39 ms |
5396 KB |
Output is correct |
17 |
Correct |
59 ms |
5832 KB |
Output is correct |
18 |
Correct |
39 ms |
5980 KB |
Output is correct |
19 |
Correct |
29 ms |
5364 KB |
Output is correct |
20 |
Correct |
46 ms |
5364 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
3584 KB |
Output is correct |
2 |
Correct |
0 ms |
3584 KB |
Output is correct |
3 |
Correct |
0 ms |
3584 KB |
Output is correct |
4 |
Correct |
0 ms |
3584 KB |
Output is correct |
5 |
Correct |
0 ms |
3584 KB |
Output is correct |
6 |
Correct |
0 ms |
3584 KB |
Output is correct |
7 |
Correct |
0 ms |
3584 KB |
Output is correct |
8 |
Correct |
0 ms |
3584 KB |
Output is correct |
9 |
Correct |
0 ms |
3584 KB |
Output is correct |
10 |
Correct |
0 ms |
3584 KB |
Output is correct |
11 |
Correct |
3 ms |
3900 KB |
Output is correct |
12 |
Correct |
3 ms |
3896 KB |
Output is correct |
13 |
Correct |
0 ms |
3732 KB |
Output is correct |
14 |
Correct |
0 ms |
3736 KB |
Output is correct |
15 |
Correct |
0 ms |
3724 KB |
Output is correct |
16 |
Correct |
0 ms |
3724 KB |
Output is correct |
17 |
Correct |
0 ms |
3732 KB |
Output is correct |
18 |
Correct |
3 ms |
3724 KB |
Output is correct |
19 |
Correct |
0 ms |
3724 KB |
Output is correct |
20 |
Correct |
0 ms |
3724 KB |
Output is correct |
21 |
Correct |
36 ms |
5460 KB |
Output is correct |
22 |
Correct |
29 ms |
5460 KB |
Output is correct |
23 |
Correct |
36 ms |
5460 KB |
Output is correct |
24 |
Correct |
33 ms |
5460 KB |
Output is correct |
25 |
Correct |
39 ms |
5588 KB |
Output is correct |
26 |
Correct |
39 ms |
5396 KB |
Output is correct |
27 |
Correct |
59 ms |
5832 KB |
Output is correct |
28 |
Correct |
39 ms |
5980 KB |
Output is correct |
29 |
Correct |
29 ms |
5364 KB |
Output is correct |
30 |
Correct |
46 ms |
5364 KB |
Output is correct |
31 |
Correct |
113 ms |
10844 KB |
Output is correct |
32 |
Correct |
116 ms |
10844 KB |
Output is correct |
33 |
Correct |
63 ms |
9564 KB |
Output is correct |
34 |
Correct |
59 ms |
9564 KB |
Output is correct |
35 |
Correct |
79 ms |
8532 KB |
Output is correct |
36 |
Correct |
66 ms |
6996 KB |
Output is correct |
37 |
Correct |
96 ms |
8316 KB |
Output is correct |
38 |
Correct |
99 ms |
8028 KB |
Output is correct |
39 |
Correct |
69 ms |
6804 KB |
Output is correct |
40 |
Correct |
76 ms |
6996 KB |
Output is correct |