QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#91486#5106. Islands from the Sky_skb_WA 6ms3816kbC++177.4kb2023-03-28 22:40:072023-03-28 22:40:09

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 22:40:09]
  • 评测
  • 测评结果:WA
  • 用时:6ms
  • 内存:3816kb
  • [2023-03-28 22:40:07]
  • 提交

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 = acosl(-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 (abs(x - other.x) > EPS && 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 = atanl(-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 * cosl(theta), p.y + d * sinl(theta)));
        ret.push_back(Point(p.x + d * cosl(theta + PI), p.y + d * sinl(theta + PI)));
        return ret;
    }
};


// int orientation(Point a, Point b, Point c) {
//     double v = a.x*(b.y-c.y)+b.x*(c.y-a.y)+c.x*(a.y-b.y);
//     if (v < 0) return -1; // clockwise
//     if (v > 0) return +1; // counter-clockwise
//     return 0;
// }

// bool cw(Point a, Point b, Point c, bool include_collinear) {
//     int o = orientation(a, b, c);
//     return o < 0 || (include_collinear && o == 0);
// }
// bool ccw(Point a, Point b, Point c, bool include_collinear) {
//     int o = orientation(a, b, c);
//     return o > 0 || (include_collinear && o == 0);
// }

// void convex_hull(vector<Point>& a, bool include_collinear = false) {
//     if (a.size() == 1)
//         return;

//     sort(a.begin(), a.end(), [](Point a, Point b) {
//         return make_pair(a.x, a.y) < make_pair(b.x, b.y);
//     });
//     Point p1 = a[0], p2 = a.back();
//     vector<Point> up, down;
//     up.push_back(p1);
//     down.push_back(p1);
//     for (int i = 1; i < (int)a.size(); i++) {
//         if (i == a.size() - 1 || cw(p1, a[i], p2, include_collinear)) {
//             while (up.size() >= 2 && !cw(up[up.size()-2], up[up.size()-1], a[i], include_collinear))
//                 up.pop_back();
//             up.push_back(a[i]);
//         }
//         if (i == a.size() - 1 || ccw(p1, a[i], p2, include_collinear)) {
//             while (down.size() >= 2 && !ccw(down[down.size()-2], down[down.size()-1], a[i], include_collinear))
//                 down.pop_back();
//             down.push_back(a[i]);
//         }
//     }

//     if (include_collinear && up.size() == a.size()) {
//         reverse(a.begin(), a.end());
//         return;
//     }
//     a.clear();
//     for (int i = 0; i < (int)up.size(); i++)
//         a.push_back(up[i]);
//     for (int i = down.size() - 2; i > 0; i--)
//         a.push_back(down[i]);
// }

int main() 
{
    // auto it = Line(1, 0, 0).getPoints(Point(0, 0), sqrt(2));
    // Wa() dbg(it[0].x) dbg(it[0].y) dbg(it[1].x) dbg(it[1].y);

    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;
            // Wa() dbg(i) dbg(v[i].x) dbg(v[i].y) dbg(ret);
        }
        if(ret < 0) {
            ret = -ret;
        }
        return ret;
    };

    ld lo = 0;
    ld hi = PI / 2;
    int step = 70;
    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 * tanl(mid));
            vector<Point> v2 = p_lines[i].second.getPoints(routes[i].second, routes[i].second.z * tanl(mid));
            v1.push_back(v2[1]);
            v1.push_back(v2[0]);
            // sort(v1.begin(), v1.end());
            // // convex_hull(v1);
            // sort(v1.begin() + 1, v1.end(), [&] (Point a, Point b) {
            //         ld theta1 = abs(v1[0].x - a.x) < EPS ? PI / 2 : atanl((v1[0].y - a.y) / (v1[0].x - a.x));
            //         ld theta2 = abs(v1[0].x - b.x) < EPS ? PI / 2 : atanl((v1[0].y - b.y) / (v1[0].x - b.x));
            //         // Wa() dbg(a.x) dbg(a.y) dbg(theta1) dbg(b.x) dbg(b.y) dbg(theta2);
            //         return abs(theta1 - theta2) > EPS && theta1 < theta2;
            //     });
            area[i] = get_area(v1);
            rect[i] = v1;
            // Wa() dbg(area[i]) dbg(v1[0].x) dbg(v1[0].y) dbg(mid);
        }

        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("%.6Lf\n", lo * 180 / PI);
    }
}

詳細信息

Test #1:

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

input:

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

output:

45.000000

result:

ok 

Test #2:

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

input:

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

output:

26.565051

result:

ok 

Test #3:

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

input:

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

output:

46.686143

result:

ok 

Test #4:

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

input:

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

output:

59.491041

result:

ok 

Test #5:

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

input:

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

output:

31.219698

result:

ok 

Test #6:

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

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.528808

result:

ok 

Test #7:

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

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.000000

result:

ok 

Test #8:

score: 0
Accepted
time: 1ms
memory: 3748kb

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.434949

result:

ok 

Test #9:

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

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: 2ms
memory: 3616kb

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: 0ms
memory: 3788kb

input:

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

output:

63.665752

result:

ok 

Test #12:

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

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.313857

result:

ok 

Test #13:

score: -100
Wrong Answer
time: 6ms
memory: 3680kb

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