QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#69664#5106. Islands from the Skyricky0129AC ✓1061ms4196kbC++174.2kb2022-12-30 03:47:222022-12-30 03:47:25

Judging History

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

  • [2023-08-10 23:21:45]
  • System Update: QOJ starts to keep a history of the judgings of all the submissions.
  • [2022-12-30 03:47:25]
  • 评测
  • 测评结果:AC
  • 用时:1061ms
  • 内存:4196kb
  • [2022-12-30 03:47:22]
  • 提交

answer

#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define vi vector<int>
#define pii pair<int,int>
#define pll pair<ll,ll>
#define vll vector<ll>
#define FOR(i,n) for(int i=0;i<n;i++)
#define rep(i, a, b) for(int i = a; i < (b); ++i)
#define all(x) begin(x), end(x)
#define sz(x) (int)(x).size()
#define pb push_back
#define f first
#define s second

const int MOD = (int)1e9+7;

template <class T> int sgn(T x) { return (x > 0) - (x < 0); }
template<class T>
struct Point {
	typedef Point P;
	T x, y;
	explicit Point(T x=0, T y=0) : x(x), y(y) {}
	bool operator<(P p) const { return tie(x,y) < tie(p.x,p.y); }
	bool operator==(P p) const { return tie(x,y)==tie(p.x,p.y); }
	P operator+(P p) const { return P(x+p.x, y+p.y); }
	P operator-(P p) const { return P(x-p.x, y-p.y); }
	P operator*(T d) const { return P(x*d, y*d); }
	P operator/(T d) const { return P(x/d, y/d); }
	T dot(P p) const { return x*p.x + y*p.y; }
	T cross(P p) const { return x*p.y - y*p.x; }
	T cross(P a, P b) const { return (a-*this).cross(b-*this); }
	T dist2() const { return x*x + y*y; }
	double dist() const { return sqrt((double)dist2()); }
	// angle to x-axis in interval [-pi, pi]
	double angle() const { return atan2(y, x); }
	P unit() const { return *this/dist(); } // makes dist()=1
	P perp() const { return P(-y, x); } // rotates +90 degrees
	P normal() const { return perp().unit(); }
	// returns point rotated 'a' radians ccw around the origin
	P rotate(double a) const {
		return P(x*cos(a)-y*sin(a),x*sin(a)+y*cos(a)); }
	friend ostream& operator<<(ostream& os, P p) {
		return os << "(" << p.x << "," << p.y << ")"; }
};

typedef Point<double> P;
struct Polygon{
    vector<P> points;
    Polygon(){}
    void add(P p){
        points.pb(p);
    }

};
double const eps = 1e-7;

double segDist(P& s, P& e, P& p) {
	if (s==e) return (p-s).dist();
	auto d = (e-s).dist2(), t = min(d,max(.0,(p-s).dot(e-s)));
	return ((p-s)*d-(e-s)*t).dist()/d;
}

bool inPolygon(vector<P> &p, P a, bool strict = false) {
	int cnt = 0, n = sz(p);
	rep(i,0,n) {
		P q = p[(i + 1) % n];
		//if (onSegment(p[i], q, a)) return !strict;
		if (segDist(p[i], q, a) <= eps) return !strict;
		cnt ^= ((a.y<p[i].y) - (a.y<q.y)) * a.cross(p[i], q) > 0;
	}
	return cnt;
}
int main()
{
    int n,m;
    scanf("%d%d",&n,&m);
    vector<Polygon> A(n);
    FOR(i,n){
        int l; 
        scanf("%d",&l);
        FOR(j,l){
            P p;
            scanf("%lf%lf",&p.x,&p.y);
            A[i].add(p);
        }
    }
    vector<vi> planes(m,vi(6,0));
    FOR(i,m){
        FOR(j,6) cin>>planes[i][j];
    }
    double l = eps, r = M_PI/2-eps;
    double ans = -1;
    while(r-l>=eps){
        double theta = (l+r)/2.0;
        vector<bool> seen(n,false);
        FOR(i,m){
            double l1 = planes[i][2]*tan(theta);
            double l2 = planes[i][5]*tan(theta);
            double xs = planes[i][0]; 
            double xe = planes[i][3];

            double ys = planes[i][1]; 
            double ye = planes[i][4];
            Point dir = P(xe-xs,ye-ys);
            dir = dir.perp();
            dir = dir.unit();
            Point d1 = dir*l1;
            Point d2 = dir*l2;

            P p1(xs,ys), p2(xs,ys), p3(xe,ye), p4(xe,ye);
            p1=p1-d1; p2=p2+d1; p3=p3+d2; p4=p4-d2;
            //cout<<theta<<endl;
            //cout<<p1<<" "<<p2<<" "<<p3<<" "<<p4<<endl;
            vector<P> hull; hull.pb(p1); hull.pb(p2); hull.pb(p3); hull.pb(p4);
            FOR(j,n){
                bool valid = true;
                FOR(k,sz(A[j].points)){
                    if(!inPolygon(hull,A[j].points[k])) valid = false;
                }
                seen[j] = seen[j] || valid;
            }
            //bool inPolygon(vector<P>& p, P a, bool strict = false){
        }
        int cc = 0;
        FOR(i,n) if(seen[i]) cc++;
        if(cc==n){
            r = theta;
            ans = theta;
        }
        else{
            l = theta;
        }
    }
    if(ans<0) printf("impossible\n");
    else{
        //cout<<ans<<endl;
        ans = ans*360/(2*M_PI);
        printf("%.8lf\n",ans);
    }

    return 0;
}

详细

Test #1:

score: 100
Accepted
time: 3ms
memory: 3984kb

input:

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

output:

45.00000000

result:

ok 

Test #2:

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

input:

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

output:

26.56505104

result:

ok 

Test #3:

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

input:

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

output:

46.68614366

result:

ok 

Test #4:

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

input:

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

output:

59.49104542

result:

ok 

Test #5:

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

input:

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

output:

31.21970233

result:

ok 

Test #6:

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

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

result:

ok 

Test #7:

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

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

result:

ok 

Test #8:

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

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

result:

ok 

Test #9:

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

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

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: 3900kb

input:

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

output:

63.66575301

result:

ok 

Test #12:

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

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

result:

ok 

Test #13:

score: 0
Accepted
time: 13ms
memory: 3836kb

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:

53.79063852

result:

ok 

Test #14:

score: 0
Accepted
time: 16ms
memory: 4196kb

input:

100 1
100
461002 481444
460618 481480
460584 481512
460833 481595
460670 481605
460545 481607
460942 481801
460526 481672
460912 481923
460765 481903
460505 481781
460430 481766
460589 481959
460593 482032
460477 481972
460440 481994
460510 482183
460285 481888
460387 482179
460246 481963
460303 482...

output:

impossible

result:

ok 

Test #15:

score: 0
Accepted
time: 17ms
memory: 3992kb

input:

100 1
100
461002 481444
460618 481480
460584 481512
460833 481595
460670 481605
460545 481607
460942 481801
460526 481672
460912 481923
460765 481903
460505 481781
460430 481766
460589 481959
460593 482032
460477 481972
460440 481994
460510 482183
460285 481888
460387 482179
460246 481963
460303 482...

output:

33.69079972

result:

ok 

Test #16:

score: 0
Accepted
time: 16ms
memory: 4164kb

input:

100 1
100
461002 481444
460618 481480
460584 481512
460833 481595
460670 481605
460545 481607
460942 481801
460526 481672
460912 481923
460765 481903
460505 481781
460430 481766
460589 481959
460593 482032
460477 481972
460440 481994
460510 482183
460285 481888
460387 482179
460246 481963
460303 482...

output:

66.40279676

result:

ok 

Test #17:

score: 0
Accepted
time: 1061ms
memory: 4104kb

input:

100 100
100
461002 481444
460618 481480
460584 481512
460833 481595
460670 481605
460545 481607
460942 481801
460526 481672
460912 481923
460765 481903
460505 481781
460430 481766
460589 481959
460593 482032
460477 481972
460440 481994
460510 482183
460285 481888
460387 482179
460246 481963
460303 4...

output:

4.18900413

result:

ok 

Test #18:

score: 0
Accepted
time: 122ms
memory: 4032kb

input:

100 11
100
461002 481444
460618 481480
460584 481512
460833 481595
460670 481605
460545 481607
460942 481801
460526 481672
460912 481923
460765 481903
460505 481781
460430 481766
460589 481959
460593 482032
460477 481972
460440 481994
460510 482183
460285 481888
460387 482179
460246 481963
460303 48...

output:

32.41193336

result:

ok 

Test #19:

score: 0
Accepted
time: 951ms
memory: 4100kb

input:

100 90
100
461002 481444
460618 481480
460584 481512
460833 481595
460670 481605
460545 481607
460942 481801
460526 481672
460912 481923
460765 481903
460505 481781
460430 481766
460589 481959
460593 482032
460477 481972
460440 481994
460510 482183
460285 481888
460387 482179
460246 481963
460303 48...

output:

5.57545389

result:

ok 

Extra Test:

score: 0
Extra Test Passed