QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#91255#5106. Islands from the Sky_skb_WA 11ms3800kbC++175.1kb2023-03-28 03:53:492023-03-28 03:53:53

Judging History

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

  • [2023-08-10 23:21:45]
  • System Update: QOJ starts to keep a history of the judgings of all the submissions.
  • [2023-03-28 03:53:53]
  • 评测
  • 测评结果:WA
  • 用时:11ms
  • 内存:3800kb
  • [2023-03-28 03:53:49]
  • 提交

answer

#include<bits/stdc++.h>
using namespace std;

using i64 = long long;
using u64 = unsigned long long;

struct debug {
#define contPrint { *this << "["; \
        int f = 0; for(auto it : x) { *this << (f?", ":""); *this << it; f = 1;} \
        *this << "]"; return *this;}
 
    ~debug(){cerr << endl;}
    template<class c> debug& operator<<(c x) {cerr << x; return *this;}
    template<class c, class d>
    debug& operator<<(pair<c, d> x) {*this << "(" << x.first << ", " << x.second << ")"; 
        return *this;}
    template<class c> debug& operator<<(vector<c> x) contPrint;
#undef contPrint
};

#define dbg(x) "[" << #x << ": " << x << "]  "
#define Wa() cerr << "[LINE: " << __LINE__ << "] -> "; debug() << 
#define FASTIO ios_base::sync_with_stdio(false); cin.tie(NULL);

using ld = long double;

const ld PI = acos(-1.0);
const ld EPS = 1e-12;

struct Point {
    ld x, y, z;
    Point() {}
    Point(ld _x, ld _y) : x(_x), y(_y) {}
    Point(ld _x, ld _y, ld _z) : x(_x), y(_y), z(_z) {}
    bool operator<(const Point& other) const {
        return x < other.x || (abs(x - other.x) < EPS && y < other.y);
    }
};

struct Line {
    ld a, b, c;
    Point p1, p2;
    ld theta;

    Line() {}
    Line(ld _a, ld _b, ld _c) : a(_a), b(_b), c(_c) {calc_theta();}
    Line(Point _p1, Point _p2) : p1(_p1), p2(_p2) {
        ld del_x = p1.x - p2.x;
        ld del_y = p1.y - p2.y;
        a = del_y;
        b = -del_x;
        c = -p1.x * del_y + p1.y * del_x;

        calc_theta();
    }

    void calc_theta() {
        if(b == 0) {
            theta = PI / 2;
        } else {
            theta = atan(-a / b);
        }
    }

    Line perpendicular(Point p) {
        ld pa, pb, pc;
        pa = b;
        pb = -a;
        pc = -pa * p.x - pb * p.y;
        return Line(pa, pb, pc);
    }

    vector<Point> getPoints(Point p, ld d) {
        vector<Point> ret;
        ret.push_back(Point(p.x + d * cos(theta), p.y + d * sin(theta)));
        ret.push_back(Point(p.x + d * cos(theta + PI), p.y + d * sin(theta + PI)));
        return ret;
    }
};

int main() 
{
    int n, m;
    scanf("%d %d", &n, &m);

    vector<vector<Point>> islands(n);
    for(int i = 0; i < n; i++) {
        int p;
        scanf("%d", &p);
        while(p--) {
            ld x, y;
            scanf("%Lf %Lf", &x, &y);
            islands[i].push_back(Point(x, y));
        }
    }

    vector<pair<Point, Point>> routes(m);
    vector<pair<Line, Line>> p_lines(m);

    for(int i = 0; i < m; i++) {
        ld x, y, z;
        scanf("%Lf %Lf %Lf", &x, &y, &z);
        routes[i].first = Point(x, y, z);

        scanf("%Lf %Lf %Lf", &x, &y, &z);
        routes[i].second = Point(x, y, z);

        p_lines[i].first = Line(routes[i].first, routes[i].second).perpendicular(routes[i].first);
        p_lines[i].second = Line(routes[i].first, routes[i].second).perpendicular(routes[i].second);
    }

    auto get_area = [] (vector<Point> v) {
        ld ret = 0;
        v.push_back(v[0]);
        for(int i = 0; i < (int)v.size()-1; i++) {
            ret += v[i].x * v[i+1].y - v[i].y * v[i+1].x;
        }
        return abs(ret);
    };

    ld lo = 0;
    ld hi = PI / 2;
    int step = 60;
    while(step--) {
        ld mid = (lo + hi) / 2;

        vector<vector<Point>> rect(m);
        vector<ld> area(m);
        for(int i = 0; i < m; i++) {
            vector<Point> v1 = p_lines[i].first.getPoints(routes[i].first, routes[i].first.z * tan(mid));
            vector<Point> v2 = p_lines[i].first.getPoints(routes[i].second, routes[i].second.z * tan(mid));
            v1.push_back(v2[0]);
            v1.push_back(v2[1]);
            sort(v1.begin(), v1.end());
            sort(v1.begin() + 1, v1.end(), [&] (Point a, Point b) {
                    ld theta1 = v1[0].x - a.x == 0 ? PI / 2 : atan((v1[0].y - a.y) / (v1[0].x - a.x));
                    ld theta2 = v1[0].x - b.x == 0 ? PI / 2 : atan((v1[0].y - b.y) / (v1[0].x - b.x));
                    return theta1 < theta2;
                });
            area[i] = get_area(v1);
            rect[i] = v1;
        }

        int cnt = 0;
        for(int i = 0; i < n; i++) {
            for(int j = 0; j < m; j++) {
                bool inside = true;
                for(auto p : islands[i]) {
                    ld cur_area = 0;
                    for(int k = 0; k < 4; k++) {
                        vector<Point> temp = {rect[j][k], rect[j][(k+1) % 4], p};
                        cur_area += get_area(temp);
                    }

                    if(cur_area - area[j] > EPS) {
                        inside = false;
                        break;
                    }
                }
                if(inside) {
                    cnt++;
                    break;
                }
            }
        }

        if(cnt == n) {
            hi = mid;
        } else {
            lo = mid;
        }
    }

    if(abs(PI / 2 - hi) < EPS) {
        puts("impossible");
    } else {
        printf("%.9Lf\n", lo * 180 / PI);
    }
}

详细

Test #1:

score: 100
Accepted
time: 2ms
memory: 3696kb

input:

1 1
3
-5 0
5 0
0 5
-10 10 10 10 10 10

output:

45.000000000

result:

ok 

Test #2:

score: 0
Accepted
time: 2ms
memory: 3768kb

input:

1 1
3
-5 0
5 0
0 5
-10 0 10 10 0 10

output:

26.565051177

result:

ok 

Test #3:

score: 0
Accepted
time: 2ms
memory: 3704kb

input:

1 1
3
-5 0
5 0
0 5
0 10 10 10 0 10

output:

46.686143342

result:

ok 

Test #4:

score: 0
Accepted
time: 2ms
memory: 3712kb

input:

1 1
3
-5 0
5 0
0 5
0 10 5 10 0 10

output:

59.491041134

result:

ok 

Test #5:

score: 0
Accepted
time: 2ms
memory: 3696kb

input:

1 1
3
-5 0
5 0
0 5
0 10 20 -10 0 10

output:

31.219698447

result:

ok 

Test #6:

score: 0
Accepted
time: 2ms
memory: 3700kb

input:

1 3
3
-5 0
5 0
0 5
-10 0 25 10 0 20
-5 10 10 10 -5 20
-4 1 100 5 10 100

output:

12.528807709

result:

ok 

Test #7:

score: 0
Accepted
time: 2ms
memory: 3768kb

input:

1 2
4
0 0
20 0
20 40
0 40
-10 30 30 30 30 30
-10 10 30 30 10 30

output:

45.000000000

result:

ok 

Test #8:

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

input:

1 4
4
0 0
20 0
20 40
0 40
-10 30 30 30 30 30
-10 20 30 30 20 30
-10 10 30 30 10 30
10 -10 30 10 50 30

output:

18.434948823

result:

ok 

Test #9:

score: 0
Accepted
time: 4ms
memory: 3600kb

input:

1 2
4
0 0
40 0
40 40
0 40
10 10 10 20 20 20
30 10 10 10 30 20

output:

impossible

result:

ok 

Test #10:

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

input:

1 3
4
0 0
20 0
20 40
0 40
-10 30 30 15 30 30
5 30 30 30 30 30
1 50 30 21 50 30

output:

impossible

result:

ok 

Test #11:

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

input:

1 1
4
0 0
40 0
40 40
0 40
-100 -100 20 100 100 10

output:

63.665752153

result:

ok 

Test #12:

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

input:

1 4
4
-10 -10
10 -10
10 10
-10 10
-100 0 10 100 0 10
0 100 10 0 -100 10
50 50 15 -50 -50 15
-50 50 15 50 -50 15

output:

43.313856658

result:

ok 

Test #13:

score: -100
Wrong Answer
time: 11ms
memory: 3684kb

input:

1 100
100
822286 0
856789 53904
986567 124632
629039 119995
732157 187986
691605 224716
728650 288493
591087 278144
801573 440668
425257 269876
614456 446428
424157 350893
645680 606334
406524 432904
545628 659551
359831 495265
367048 578376
251435 457360
319990 680014
336526 849968
214009 658652
23...

output:

impossible

result:

wrong answer