QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#658247#7906. Almost ConvexLeoGTL 3ms129216kbC++202.4kb2024-10-19 16:28:102024-10-19 16:28:10

Judging History

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

  • [2024-10-19 16:28:10]
  • 评测
  • 测评结果:TL
  • 用时:3ms
  • 内存:129216kb
  • [2024-10-19 16:28:10]
  • 提交

answer

#include <iostream>
#include <algorithm>
#include <cmath>
#include <vector>
#define int long long
using namespace std;
const int N = 2e3+10;
int n, p, ans;
struct Point {
    int x, y;
    bool inside = true;
    double angle[N][2];
    Point(int xx = 0, int yy = 0) : x(xx), y(yy) {}
    bool operator==(const Point &b) const {
        return x == b.x && y == b.y;
    }
} list[N], stk[N];
int cross(Point p0, Point p1, Point p2) {
    return (p1.x - p0.x) * (p2.y - p0.y) - (p2.x - p0.x) * (p1.y - p0.y);
}
bool cmp(Point a, Point b) {
    if (a.x != b.x) return a.x < b.x;
    return a.y < b.y;
}
 
int dis(Point a, Point b) {
    return (b.x - a.x) * (b.x - a.x) + (b.y - a.y) * (b.y - a.y);
}
double cos(Point a, Point b, Point c) {
    return (dis(a, b) + dis(b, c) - dis(a, c)) / (2 * sqrt(dis(a, b)) * sqrt(dis(b, c)));
}
void andrew() {
    p = 1;
    stk[0] = list[0], stk[1] = list[1];
    for (int i = 2; i < n; ++i) {
        while (p > 0 && cross(stk[p - 1], stk[p], list[i]) <= 0) --p;
        stk[++p] = list[i];
    }
    stk[++p] = list[n - 2];
    for (int i = n - 3; i >= 0; --i) {
        while (p > 0 && cross(stk[p - 1], stk[p], list[i]) <= 0) --p;
        stk[++p] = list[i];
    }
}
signed main(){
    ios::sync_with_stdio(0);
    cin >> n;
    for (int i = 0; i < n; ++i) cin >> list[i].x >> list[i].y;
    sort(list, list + n, cmp);
    andrew();
    vector<Point> ins;
    for (int i = 0; i < n; ++i) {   // for each point
        for (int j = 0; j < p; ++j) {   // for each edge
            if (list[i] == stk[j]) {
                list[i].inside = false;
                break;
            }
            list[i].angle[j][0] = cos(list[i], stk[j], stk[j + 1]);
            list[i].angle[j][1] = cos(list[i], stk[j + 1], stk[j]);
        }
        if (list[i].inside) ins.push_back(list[i]);
    }
    for (int i = 0; i < p; ++i) {
        sort(ins.begin(), ins.end(), [&](Point a, Point b){
            return a.angle[i][0] > b.angle[i][0];
        });
        double angle2 = 1;
        for (auto& po : ins) {
            if (po == ins[0]) {
                angle2 = po.angle[i][1];
                ans++;
            }
            else {
                if (po.angle[i][1] > angle2) {
                    ans++;
                }
            }
        }
    }
    cout << ans + 1 << endl;
    return 0;
}

详细

Test #1:

score: 100
Accepted
time: 0ms
memory: 129184kb

input:

7
1 4
4 0
2 3
3 1
3 5
0 0
2 4

output:

9

result:

ok 1 number(s): "9"

Test #2:

score: 0
Accepted
time: 3ms
memory: 128908kb

input:

5
4 0
0 0
2 1
3 3
3 1

output:

5

result:

ok 1 number(s): "5"

Test #3:

score: 0
Accepted
time: 0ms
memory: 128876kb

input:

3
0 0
3 0
0 3

output:

1

result:

ok 1 number(s): "1"

Test #4:

score: 0
Accepted
time: 0ms
memory: 129216kb

input:

6
0 0
3 0
3 2
0 2
1 1
2 1

output:

7

result:

ok 1 number(s): "7"

Test #5:

score: 0
Accepted
time: 0ms
memory: 128960kb

input:

4
0 0
0 3
3 0
3 3

output:

1

result:

ok 1 number(s): "1"

Test #6:

score: -100
Time Limit Exceeded

input:

2000
86166 617851
383354 -277127
844986 386868
-577988 453392
-341125 -386775
-543914 -210860
-429613 606701
-343534 893727
841399 339305
446761 -327040
-218558 -907983
787284 361823
950395 287044
-351577 -843823
-198755 138512
-306560 -483261
-487474 -857400
885637 -240518
-297576 603522
-748283 33...

output:


result: