Submission #226365

#TimeUsernameProblemLanguageResultExecution timeMemory
226365BruteforcemanPrinted Circuit Board (CEOI12_circuit)C++11
15 / 100
225 ms5740 KiB
#include <bits/stdc++.h> using namespace std; const int maxn = 1e5 + 5; int n; struct point { long long x, y; point () {} point (long long x, long long y) : x(x), y(y) {} point operator + (point p) const { return point(x + p.x, y + p.y); } point operator - (point p) const { return point(x - p.x, y - p.y); } } a[maxn]; int ord[maxn]; long long cross(point p, point q) { return p.x * q.y - p.y * q.x; } long long dot(point p, point q) { return p.x * q.x + p.y * q.y; } bool inSegment(point a, point b, point c) { return cross(c - a, b - a) == 0 && dot(a - b, a - b) >= max(dot(a - c, a - c), dot(c - b, c - b)); } int side(point a, point b, point c) { long long x = cross(b - a, c - a); if(x > 0) return 1; else if (x < 0) return -1; else return 0; } bool intersect(point a, point b, point c, point d) { if(side(a, b, c) * side(a, b, d) == -1 && side(c, d, a) * side(c, d, b) == -1) return true; for(auto i : {c, d}) if(inSegment(a, b, i)) return true; for(auto i : {a, b}) if(inSegment(c, d, i)) return true; return false; } pair <long long, long long> sect(point a, point b, point c) { point f = b - a; long long p = cross(a, f) * c.x; long long q = cross(c, f); if(q < 0) { q *= -1; p *= -1; } return make_pair(p, q); } point piv; struct data { int i, j; data () {} data (int i, int j) : i(i), j(j) {} }; bool operator < (data p, data q) { pair <long long, long long> e = sect(a[p.i], a[p.j], piv); pair <long long, long long> f = sect(a[q.i], a[q.j], piv); if(e.first * f.second == e.second * f.first) { return make_pair(p.i, p.j) < make_pair(q.i, q.j); } else { return e.first * f.second < e.second * f.first; } } int main() { cin >> n; for(int i = 0; i < n; i++) { cin >> a[i].x >> a[i].y; ord[i] = i; } auto cmp = [&] (int i, int j) { return cross(a[i], a[j]) > 0 || (cross(a[i], a[j]) == 0 && dot(a[i], a[i]) < dot(a[j], a[j])); }; sort(ord, ord + n, cmp); vector <int> res; set <data> can; int cur = 0; while(cur < n) { int x = ord[cur]; for(int i : {-1, 1}) { int y = (x + i + n) % n; if(cross(a[x], a[y]) < 0) { can.erase(data(y, x)); } } piv = a[x]; if(cur == 0 || cross(a[ord[cur - 1]], a[ord[cur]]) != 0) { //cout << "now at " << x + 1 << endl; //for(auto g : can) { // cout << g.i + 1 << ' ' << g.j + 1 << endl; //} if(can.empty() || !intersect(point(0, 0), a[x], a[can.begin() -> i], a[can.begin() -> j])) res.emplace_back(x+1); } for(int i : {-1, 1}) { int y = (x + i + n) % n; if(cross(a[x], a[y]) > 0) { can.insert(data(x, y)); } } cur++; } sort(res.begin(), res.end()); cout << res.size() << endl; for(auto i : res) cout << i << " "; cout << endl; return 0; }
#Verdict Execution timeMemoryGrader output
Fetching results...