QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#279016#7906. Almost Convexucup-team1508#Compile Error//C++204.1kb2023-12-08 01:24:432023-12-08 01:24:43

Judging History

你现在查看的是最新测评结果

  • [2023-12-08 01:24:43]
  • 评测
  • [2023-12-08 01:24:43]
  • 提交

answer

#include<bits/stdc++.h>
#define F(i, a, b) for(int i = a; i <= b; i ++)
#define Fd(i, a, b) for(int i = a; i >= b; i --)
#define int long long
#define pii pair<int, int>
#define fi first
#define se second
using namespace std;
typedef long long db;
const db eps = 0;
int sgn(db x) {
    if(fabs(x) <= eps) return 0;
    else return x < 0 ? -1 : 1;
}
struct point {
    db x, y;
    int id;
    point() {}
    point(db x, db y, int id) : x(x), y(y), id(id) {}
    point operator + (point B) {return point(x + B.x, y + B.y, id);}
    point operator - (point B) {return point(x - B.x, y - B.y, id);}
    bool operator == (point B) {return sgn(x - B.x) == 0 && sgn(y - B.y) == 0;}
    bool operator < (point B) {return sgn(x - B.x) < 0 || (sgn(x - B.x) == 0 && sgn(y - B.y) < 0);}
};
db dis(point A, point B) {return sqrt((A.x - B.x) * (A.x - B.x) + (A.y - B.y) * (A.y - B.y));}
typedef point vct;
db cross(point A, point B) {return A.x * B.y - A.y * B.x;}
db dot(vct A, vct B) {return A.x * B.x + A.y * B.y;}
db len(vct A) {return sqrt(dot(A, A));}
db len2(vct A) {return dot(A, A);}
db angle(vct A, vct B) {return acos(dot(A, B) / len(A) / len(B));}
db cross(vct A, vct B) {return A.x * B.y - A.y * B.x;}
db area2(point A, point B, point C) {return fabs(cross(B - A, C - A));}   //平行四边形面积
bool get_region(point a) {return a.y <= 0 && (a.x < 0 || a.y < 0);}
point o = {0, 0, 0};
bool get_region(point a) {return a.y <= 0 && (a.x < 0 || a.y < 0);}
bool cmp1(point a, point b) {
    point p = a - o, q = b - o;
    int r1 = get_region(p), r2 = get_region(q);
    if(r1 != r2) return r1 < r2;
    if(cross(p, q) == 0) return dot(p, p) < dot(q, q);
    return cross(p, q) > 0;
}
const int N = 2005;

int convex_hull(vector<point> p, int n, int *ch) {
    int v = 0;
    F(i, 0, n - 1) {
        while(v >= 2 && sgn(cross(p[ch[v - 1]] - p[ch[v - 2]], p[i] - p[ch[v - 1]])) <= 0) v --;
        ch[v ++] = i;
    } int j = v;
    Fd(i, n - 2, 0) {
        while(v > j && sgn(cross(p[ch[v - 1]] - p[ch[v - 2]], p[i] - p[ch[v - 1]])) <= 0) v --;
        ch[v ++] = i;
    } 
    return n > 1 ? v - 1 : v;
}

int ch[N], vst[N];

void sol() {
    int n; cin >> n;
    vector<point> a(n);
    F(i, 0, n - 1) {
        int x, y; cin >> x >> y;
        a[i].x = x, a[i].y = y;
    }
    sort(a.begin(), a.end());
    int m = convex_hull(a, n, ch);
    F(i, 0, n - 1) a[i].id = i;
    F(i, 0, m - 1) vst[ch[i]] = 1;
    int res = 0;

    F(i, 0, m - 1) {
        int l = ch[i], r = ch[(i + 1) % m];
        auto b = a, c = a;
        vector<point> tmp(n);
        o = a[l];
        sort(b.begin(), b.end(), cmp1);
        o = a[r];
        sort(c.begin(), c.end(), cmp1);
        reverse(c.begin(), c.end());
        int b0, b1;
        F(j, 0, n - 1) if(b[j].id == a[r].id) {
            b0 = (j + 1) % n;
            break;
        }
        F(j, 0, n - 1) if(c[j].id == a[l].id) {
            b1 = (j + 1) % n;
            break;
        }
        vector<int> pos1(n), pos2(n), ok(n);
        int cnt = 0, tot = 0;
        for(int j = b0; tot < n; j = (j + 1) % n) {
            tot ++;
            tmp[cnt].x = b[j].x, tmp[cnt].y = b[j].y, tmp[cnt ++].id = b[j].id;
        } b = tmp;
        F(j, 0, n - 1) pos1[b[j].id] = j;
        cnt = 0, tot = 0;
        for(int j = b1; tot < n; j = (j + 1) % n) {
            tot ++;
            tmp[cnt].x = c[j].x, tmp[cnt].y = c[j].y, tmp[cnt ++].id = c[j].id;
        } c = tmp;
        F(j, 0, n - 1) pos2[c[j].id] = j;

        int mn = n;
        F(j, 0, n - 1) {
            if(vst[b[j].id]) continue;
            if(mn <= pos2[b[j].id]) ok[b[j].id] = 1;
            mn = min(mn, pos2[b[j].id]);
        } mn = n;
        F(j, 0, n - 1) {
            if(vst[c[j].id]) continue;
            if(mn <= pos1[c[j].id]) ok[c[j].id] = 1;
            mn = min(mn, pos1[c[j].id]);
        } 

        F(j, 0, n - 1) if(! ok[j] && ! vst[j]) res ++;
    }

    cout << res + 1 << "\n";
}

signed main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    sol();
    return 0;
}
/*
7
1 4
4 0
2 3
3 1
3 5
0 0
2 4

*/

Details

answer.code:32:4: error: redefinition of ‘db cross(vct, vct)’
   32 | db cross(vct A, vct B) {return A.x * B.y - A.y * B.x;}
      |    ^~~~~
answer.code:27:4: note: ‘db cross(point, point)’ previously defined here
   27 | db cross(point A, point B) {return A.x * B.y - A.y * B.x;}
      |    ^~~~~
answer.code:36:6: error: redefinition of ‘bool get_region(point)’
   36 | bool get_region(point a) {return a.y <= 0 && (a.x < 0 || a.y < 0);}
      |      ^~~~~~~~~~
answer.code:34:6: note: ‘bool get_region(point)’ previously defined here
   34 | bool get_region(point a) {return a.y <= 0 && (a.x < 0 || a.y < 0);}
      |      ^~~~~~~~~~