|
| 1 | +```cpp |
| 2 | +#include <bits/stdc++.h> |
| 3 | +using namespace std; |
| 4 | + |
| 5 | +vector<pair<int, int>> p, u, l; |
| 6 | +int N, K; |
| 7 | + |
| 8 | +int ccw(pair<long long, long long> a, pair<long long, long long> b, pair<long long, long long> c) { |
| 9 | + auto [ax, ay] = a; |
| 10 | + auto [bx, by] = b; |
| 11 | + auto [cx, cy] = c; |
| 12 | + long long res = ax*by + bx*cy + cx*ay - (ax*cy + bx*ay + cx*by); |
| 13 | + if(res > 0) return 1; |
| 14 | + if(res < 0) return -1; |
| 15 | + return 0; |
| 16 | +} |
| 17 | + |
| 18 | +int main() { |
| 19 | + cin.tie(0)->sync_with_stdio(0); |
| 20 | + |
| 21 | + cin>>N>>K; |
| 22 | + if(N%K) return cout<<"NO",0; |
| 23 | + p.resize(N); |
| 24 | + for(auto &[x,y]:p) cin>>x>>y; |
| 25 | + int _x, _y; |
| 26 | + cin>>_x>>_y; |
| 27 | + for(auto &[x,y]:p) { |
| 28 | + x-=_x, y-=_y; |
| 29 | + if(y < 0 || (y == 0 && x < 0)) l.emplace_back(x,y); |
| 30 | + else u.emplace_back(x,y); |
| 31 | + } |
| 32 | + |
| 33 | + sort(u.begin(), u.end(), [](auto a, auto b) -> bool { |
| 34 | + return ccw({0,0}, a, b) < 0; |
| 35 | + }); |
| 36 | + sort(l.begin(), l.end(), [](auto a, auto b) -> bool { |
| 37 | + return ccw({0,0}, a, b) < 0; |
| 38 | + }); |
| 39 | + |
| 40 | + deque<int> a; |
| 41 | + for(int i=1;i<u.size();i++) { |
| 42 | + int cnt = 1; |
| 43 | + while(i<u.size() && !ccw({0,0}, u[i-1], u[i])) cnt++, i++; |
| 44 | + a.push_back(cnt); |
| 45 | + } |
| 46 | + for(int i=1;i<l.size();i++) { |
| 47 | + int cnt = 1; |
| 48 | + while(i<l.size() && !ccw({0,0}, l[i-1], l[i])) cnt++, i++; |
| 49 | + a.push_back(cnt); |
| 50 | + } |
| 51 | + |
| 52 | + for(int c=0;c<N;c++) { |
| 53 | + a.push_back(a.front()); |
| 54 | + a.pop_front(); |
| 55 | + int cur = 0; |
| 56 | + bool poss = 1; |
| 57 | + for(int i:a) { |
| 58 | + cur += i; |
| 59 | + if(cur == N/K) cur = 0; |
| 60 | + else if(cur > N/K) { |
| 61 | + poss = 0; |
| 62 | + break; |
| 63 | + } |
| 64 | + } |
| 65 | + if(poss) return cout<<"YES", 0; |
| 66 | + } |
| 67 | + cout<<"NO"; |
| 68 | + |
| 69 | +} |
| 70 | +``` |
0 commit comments