QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#592493#7081. Cut the PlaneAfterlifeTL 665ms3868kbC++209.2kb2024-09-26 22:57:302024-09-26 22:57:31

Judging History

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

  • [2024-09-26 22:57:31]
  • 评测
  • 测评结果:TL
  • 用时:665ms
  • 内存:3868kb
  • [2024-09-26 22:57:30]
  • 提交

answer

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

#define int long long

const int N=1e2+1e1+7,L=12;

struct P{
    int x,y;
    P(int _x=0,int _y=0){x=_x,y=_y;}
};

P operator *(const P &a,const int &b)
{
    return {a.x*b,a.y*b};
}

P operator -(const P &a,const P &b)
{
    return {a.x-b.x,a.y-b.y};
}

P operator +(const P &a,const P &b)
{
    return {a.x+b.x,a.y+b.y};
}

int T;

int sgn(int x)
{
    return x<-0?-1:(x>0);
}

int det(P a,P b)
{
    return a.x*b.y-a.y*b.x;
}

int dot(P a,P b)
{
    return a.x*b.x+a.y*b.y;
}

int in_seg(P a,P b,P c)
{
    return sgn(det(b-a,c-a))==0&&sgn(dot(a-c,b-c))<=0;
}

int segment_intersection(P a,P b,P c,P d)
{
    if(sgn(det(b-a,c-a))*sgn(det(b-a,d-a))==-1&&sgn(det(d-c,a-c))*sgn(det(d-c,b-c))==-1)
        return 1;
    if(in_seg(a,b,d)||in_seg(a,b,c)||in_seg(c,d,a)||in_seg(c,d,b))
        return 1;
    return 0;
}

signed main()
{
    ios::sync_with_stdio(false);
    cin.tie(0);
    cin>>T;
    while(T--)
    {
        int n;
        cin>>n;
        // n=100;
        vector<P>p(n);
        for(auto &[x,y]:p)
        {
            // x=rand()%10000,y=rand()%10000;
            // x*=2,y*=2;
            cin>>x>>y;
        }
        if(n==1)
        {
            cout<<(int)1e8<<" "<<(int)1e8<<" "<<(int)1e8+1<<" "<<(int)1e8<<"\n";
            continue;
        }
        sort(p.begin(),p.end(),[&](const P &a,const P &b){
            if(a.y!=b.y)
                return a.y<b.y;
            return a.x>b.x;
        });
        int h=n/2;
        P m=(p[h-1]+p[h]);
        m.x/=2,m.y/=2;
        vector<pair<P,P> >ans;
        P A=m+P(1e8,0);
        P B=m+P(-1e8,0);
        P mab,mcd;
        while(1)
        {
            mab=A,mcd=B;
            mab.x+=rand()%L-L/2;
            mab.y+=rand()%L-L/2;
            mcd.x+=rand()%L-L/2;
            mcd.y+=rand()%L-L/2;
            int ok=1;
            for(int i=0;i<n;i++)
            {
                if(in_seg(mab,mcd,p[i]))
                {
                    ok=0;
                    break;
                }
            }
            for(int i=0;i<h;i++)
            {
                if(!ok)
                    break;
                for(int j=h;j<n;j++)
                    if(!segment_intersection(p[i],p[j],mab,mcd))
                    {
                        ok=0;
                        break;
                    }
            }
            if(ok)
                break;
        }
        ans.push_back({mab,mcd});
        random_shuffle(p.begin(),p.begin()+h);
        random_shuffle(p.begin()+h,p.begin()+n);
        // sort(p.begin(),p.begin()+h,[&](const P &a,const P &b){
        //     if(a.x!=b.x)
        //         return a.x<b.x;
        //     return a.y<b.y;
        // });
        // sort(p.begin()+h,p.begin()+n,[&](const P &a,const P &b){
        //     if(a.x!=b.x)
        //         return a.x<b.x;
        //     return a.y<b.y;
        // });
        // int u=0,v=h;
        using pii=pair<int,int>;
        deque<pii> q1,q2;
        for(int i=0;i<h;i++)
            for(int j=i+1;j<h;j++)
                q1.push_back({i,j});
        for(int i=h;i<n;i++)
            for(int j=i+1;j<n;j++)
                q2.push_back({i,j});
        while(!q1.empty()&&!q2.empty())
        {
            while(q1.size())
            {
                auto [a,b]=q1.front();
                int ok=0;
                for(auto [u,v]:ans)
                    if(segment_intersection(p[a],p[b],u,v))
                    {
                        ok=1;
                        break;
                    }
                if(ok)
                    q1.pop_front();
                else
                    break;
            }
            
            while(q2.size())
            {
                auto [a,b]=q2.front();
                int ok=0;
                for(auto [u,v]:ans)
                    if(segment_intersection(p[a],p[b],u,v))
                    {
                        ok=1;
                        break;
                    }
                if(ok)
                    q2.pop_front();
                else
                    break;
            }
            if(!q1.size()||!q2.size())
                break;
            auto [ia,ib]=q1.front();
            auto [ic,id]=q2.front();
            q1.pop_front(),q2.pop_front();
            P a=p[ia],b=p[ib],c=p[ic],d=p[id];
            P mab=a;
            // mab.x/=2,mab.y/=2;
            P mcd=c;
            // mcd.x/=2,mcd.y/=2;
            // P dir=a+b-c-d;
            P dir=a-c;
            mab=mab+dir*50000;
            mcd=mcd-dir*50000;
            P A=mab,B=mcd;
            int lim=10,ok=1;
            while(lim--)
            {
                mab=A;
                mcd=B;
                mab.x+=rand()%L-L/2;
                mcd.x+=rand()%L-L/2;
                mab.y+=rand()%L-L/2;
                mcd.y+=rand()%L-L/2;
                ok=1;
                for(int i=0;i<n;i++)
                {
                    if(!ok)
                        break;
                    if(in_seg(mab,mcd,p[i]))
                        ok=0;
                }
                if(!segment_intersection(mab,mcd,a,b)||!segment_intersection(mab,mcd,c,d))
                    ok=0;
                if(ok)
                    break;
            }
            if(!ok)
            {
                q1.push_back({ia,ib});
                q2.push_front({ic,id});
            }
            else
                ans.push_back({mab,mcd});
        }
        while(q1.size())
        {
            while(q1.size())
            {
                auto [a,b]=q1.front();
                int ok=0;
                for(auto [u,v]:ans)
                    if(segment_intersection(p[a],p[b],u,v))
                    {
                        ok=1;
                        break;
                    }
                if(ok)
                    q1.pop_front();
                else
                    break;
            }
            if(!q1.size())
                break;
            P a=p[q1.front().first],b=p[q1.front().second];
            q1.pop_front();
            P m=(a+b);
            m.x/=2,m.y/=2;
            P A=P(m.x,m.y+1e8),B=P(m.x,m.y-1e8);
            P mab,mcd;
            while(1)
            {
                mab=A;
                mcd=B;
                mab.x+=rand()%L-L/2;
                mcd.x+=rand()%L-L/2;
                mab.y+=rand()%L-L/2;
                mcd.y+=rand()%L-L/2;
                int ok=1;
                for(int i=0;i<n;i++)
                {
                    if(!ok)
                        break;
                    if(in_seg(mab,mcd,p[i]))
                        ok=0;
                }
                if(!segment_intersection(mab,mcd,a,b))
                    ok=0;
                if(ok)
                    break;

            }
            ans.push_back({mab,mcd});

        }
        while(q2.size())
        {
            while(q2.size())
            {
                auto [a,b]=q2.front();
                int ok=0;
                for(auto [u,v]:ans)
                    if(segment_intersection(p[a],p[b],u,v))
                    {
                        ok=1;
                        break;
                    }
                if(ok)
                    q2.pop_front();
                else
                    break;
            }
            if(!q2.size())
                break;
            P a=p[q2.front().first],b=p[q2.front().second];
            q2.pop_front();
            P m=(a+b);
            m.x/=2,m.y/=2;
            P A=P(m.x,m.y+1e8),B=P(m.x,m.y-1e8);
            
            P mab,mcd;
            while(1)
            {
                mab=A;
                mcd=B;
                mab.x+=rand()%L-L/2;
                mcd.x+=rand()%L-L/2;
                mab.y+=rand()%L-L/2;
                mcd.y+=rand()%L-L/2;
                int ok=1;
                for(int i=0;i<n;i++)
                {
                    if(!ok)
                        break;
                    if(in_seg(mab,mcd,p[i]))
                        ok=0;
                }
                if(!segment_intersection(mab,mcd,a,b))
                    ok=0;
                if(ok)
                    break;

            }
            ans.push_back({mab,mcd});

        }
        for(auto &[a,b]:ans)
        {
            cout<<a.x<<" "<<a.y<<" "<<b.x<<" "<<b.y<<"\n";
        }
        int z=1e8;
        int tot=(n+1)/2;
        while(ans.size()<tot)
        {
            cout<<(int)z<<" "<<(int)z<<" "<<(int)z+1<<" "<<(int)z<<"\n";
            z++;
            tot--;
        }

        // int ok=1;
        // // ok&=ans.size()==(n+1)/2;
        // for(int i=0;i<n;i++)
        // {
        //     for(auto [u,v]:ans)
        //     {
        //         if(in_seg(u,v,p[i]))
        //             ok=0;
        //     }
        //     for(int j=i+1;j<n;j++)
        //     {
        //         int flag=0;
        //         for(auto [u,v]:ans)
        //             if(segment_intersection(p[i],p[j],u,v))
        //                 flag=1;
        //         ok&=flag;
        //     }
        // }
        // cout<<ok<<endl;
    }
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

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

input:

2
3
0 0
2 1
4 0
4
0 1
1 0
2 1
1 2

output:

99999998 4 -99999995 -4
-1 100000005 3 -100000004
99999997 3 -99999995 -1
49997 -50003 -49996 50007

result:

ok 2 cases

Test #2:

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

input:

4
2
0 0
3 0
3
0 0
3 0
3 3
4
0 0
3 0
3 3
0 3
4
0 0
3 0
1 1
0 3

output:

99999997 4 -99999996 -4
99999999 4 -99999995 -4
3 99999996 -2 -100000004
100000003 1 -99999999 2
3 -150000 2 149997
99999998 0 -99999997 2
-50000 -50003 50001 50004

result:

ok 4 cases

Test #3:

score: 0
Accepted
time: 229ms
memory: 3828kb

input:

18093
1
-883 286
1
922 -705
3
614 -576
611 -576
607 -572
10
748 868
751 873
752 869
747 864
743 865
746 864
745 868
746 874
750 869
742 866
5
494 618
491 613
497 617
492 619
498 611
10
-639 -359
-634 -358
-642 -355
-638 -361
-638 -357
-634 -357
-641 -360
-639 -353
-633 -362
-642 -359
9
-327 -157
-32...

output:

100000000 100000000 100000001 100000000
100000000 100000000 100000001 100000000
100000608 -572 -99999385 -580
611 99999423 604 -100000577
100000742 870 -99999250 866
-349256 -199135 350751 200872
-349261 -199136 350746 200864
-149259 -449139 150749 450877
50750 -199132 -49259 200867
100000494 611 -9...

result:

ok 18093 cases

Test #4:

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

input:

18174
9
398 -265
397 -261
399 -265
399 -267
404 -268
402 -269
400 -262
398 -266
401 -261
3
-128 -721
-128 -723
-127 -722
8
-28 62
-25 56
-30 61
-25 61
-30 55
-26 59
-24 57
-28 56
8
-91 -145
-88 -148
-92 -143
-88 -142
-91 -146
-93 -149
-93 -145
-94 -141
7
375 -521
370 -517
371 -519
370 -520
368 -516
...

output:

100000392 -265 -99999604 -267
150400 -200266 -149602 199735
150402 -200270 -149601 199737
100398 -300265 -99603 299740
402 99999743 400 -100000257
99999874 -723 -100000126 -722
-126 99999273 -129 -100000722
99999971 53 -100000020 63
99974 -249942 -100030 250061
-33 -299945 -23 300064
49979 -149946 -...

result:

ok 18174 cases

Test #5:

score: 0
Accepted
time: 208ms
memory: 3604kb

input:

18276
3
934 -359
916 -349
925 -349
9
-518 -436
-520 -428
-509 -430
-523 -432
-511 -417
-506 -427
-508 -420
-516 -432
-521 -426
1
762 -777
4
46 -219
32 -208
45 -215
43 -226
5
275 572
269 571
284 563
285 558
274 572
10
-196 886
-193 886
-187 888
-184 905
-198 890
-199 894
-203 888
-186 899
-186 900
-1...

output:

100000930 -350 -99999068 -353
921 99999645 924 -100000346
99999487 -424 -100000510 -435
-150526 -200432 149485 199566
549490 -100433 -550519 99575
-600522 -450439 599488 449569
-522 99999578 -512 -100000418
100000000 100000000 100000001 100000000
100000048 -213 -99999957 -222
-99952 -550228 100040 5...

result:

ok 18276 cases

Test #6:

score: 0
Accepted
time: 211ms
memory: 3660kb

input:

18212
6
-133 -816
-133 -826
-122 -822
-127 -828
-132 -815
-131 -832
5
-341 -553
-343 -558
-336 -541
-343 -557
-347 -557
1
-36 -721
8
5 -44
9 -33
16 -35
3 -38
1 -42
1 -40
0 -36
6 -36
4
235 210
242 214
248 214
241 226
6
-779 -432
-765 -419
-773 -416
-765 -427
-782 -422
-779 -426
1
-409 -252
5
69 -343
...

output:

99999876 -829 -100000131 -823
-250133 -300830 249878 299176
249873 -650829 -250132 649182
99999651 -553 -100000342 -561
-100339 -200556 99654 199444
-337 99999447 -341 -100000547
100000000 100000000 100000001 100000000
100000008 -40 -99999999 -35
-549993 -450040 550020 449970
-249999 -200043 250006 ...

result:

ok 18212 cases

Test #7:

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

input:

1958
39
-223 -168
-133 -180
-269 -262
-227 -341
-147 -282
-220 -166
-264 -362
-253 -307
-160 -353
-292 -210
-216 -356
-164 -212
-114 -347
-295 -181
-211 -279
-272 -189
-140 -179
-173 -187
-131 -265
-174 -356
-298 -227
-164 -342
-114 -235
-149 -231
-300 -169
-139 -285
-119 -323
-205 -183
-253 -222
-1...

output:

99999715 -254 -100000283 -257
-6750282 -4250316 6749849 4249769
-1350175 -2950296 1349854 2949770
-2150178 -5500287 2149864 5499822
4749827 -5450335 -4750264 5449772
699747 -3950308 -700273 3949771
2899857 -4950279 -2900208 4949811
2899848 -4950282 -2900202 4949821
4449859 -2300282 -4450228 2299761
...

result:

ok 1958 cases

Test #8:

score: 0
Accepted
time: 457ms
memory: 3680kb

input:

2023
75
71 -22
93 -4
171 -34
132 50
115 105
35 -21
56 70
51 -45
44 71
153 -3
106 12
139 9
86 -28
127 -30
100 94
47 100
105 15
151 85
186 31
165 -56
35 26
164 98
164 -48
33 -1
113 -52
149 42
27 40
89 -16
88 7
46 -41
130 -10
167 43
88 -23
172 17
143 76
92 -6
81 -15
107 -58
168 2
15 31
57 -52
156 56
11...

output:

100000069 13 -99999933 12
4200167 -7750052 -4199921 7750110
4200166 -7750053 -4199924 7750110
-1199845 -2500003 1200175 2500047
-7399969 -2249998 7400171 2250041
3350167 -5399996 -3349896 5400110
3350166 -5400003 -3349904 5400109
-3049897 -6250061 3050168 6250065
-3049889 -6250062 3050172 6250069
35...

result:

ok 2023 cases

Test #9:

score: 0
Accepted
time: 453ms
memory: 3740kb

input:

1998
58
-199 202
-191 250
-209 243
-189 197
-182 192
-176 249
-168 224
-211 202
-178 239
-226 228
-176 221
-184 223
-188 219
-190 242
-199 236
-206 219
-205 188
-183 230
-202 244
-213 243
-230 209
-203 261
-186 237
-201 222
-200 241
-179 261
-204 256
-185 210
-182 233
-204 214
-179 210
-168 241
-232...

output:

99999782 228 -100000219 222
949839 -2249800 -950187 2250251
949829 -2249801 -950191 2250249
949832 -2249800 -950187 2250251
-650185 -1699778 649828 1700253
-500180 -2549800 499827 2550256
-300210 -1099776 299795 1100246
-300204 -1099780 299800 1100243
-300207 -1099779 299802 1100246
-1850218 -139978...

result:

ok 1998 cases

Test #10:

score: 0
Accepted
time: 34ms
memory: 3604kb

input:

100000
1
-756 684
1
698 -384
1
-668 -920
1
-565 -818
1
31 -211
1
760 -246
1
-588 -604
1
-813 78
1
-340 850
1
-357 -772
1
-312 -200
1
752 -752
1
-230 727
1
961 255
1
146 581
1
956 -259
1
479 -760
1
967 -612
1
-760 -97
1
-953 643
1
518 137
1
-950 52
1
-796 193
1
-732 661
1
-716 671
1
275 266
1
235 468...

output:

100000000 100000000 100000001 100000000
100000000 100000000 100000001 100000000
100000000 100000000 100000001 100000000
100000000 100000000 100000001 100000000
100000000 100000000 100000001 100000000
100000000 100000000 100000001 100000000
100000000 100000000 100000001 100000000
100000000 100000000 ...

result:

ok 100000 cases

Test #11:

score: 0
Accepted
time: 635ms
memory: 3868kb

input:

1000
100
700 -782
717 -672
709 -763
725 -677
704 -682
694 -787
696 -758
649 -770
653 -669
570 -771
546 -682
569 -707
557 -807
621 -708
682 -651
707 -693
679 -655
665 -696
725 -745
686 -770
567 -801
604 -689
643 -658
741 -753
636 -772
726 -719
653 -691
598 -719
702 -774
729 -674
613 -615
649 -702
611...

output:

100000619 -712 -99999386 -701
-2899379 -2650710 2900676 2649349
-2899375 -2650706 2900675 2649340
2300725 -4500751 -2299327 4499340
2300725 -4500744 -2299321 4499345
2350651 -7050768 -2349395 7049371
2350643 -7050771 -2349399 7049375
4200683 -7050766 -4199400 7049375
3350690 -7700768 -3349383 769938...

result:

ok 1000 cases

Test #12:

score: 0
Accepted
time: 665ms
memory: 3644kb

input:

1000
100
-159 240
-179 66
-191 220
-122 120
-183 201
-220 221
-207 234
-247 152
-89 167
-125 224
-171 231
-223 84
-139 185
-219 193
-225 115
-215 170
-199 183
-218 142
-117 195
-84 110
-145 232
-147 118
-220 233
-122 165
-198 60
-232 100
-116 187
-263 183
-155 93
-198 73
-195 137
-132 71
-172 135
-1...

output:

99999769 157 -100000227 155
-3450193 -8499942 3449874 8500230
-3450187 -8499942 3449884 8500226
-4700221 -6849918 4699883 6850223
-4700213 -6849917 4699875 6850228
1549876 -8899936 -1550163 8900235
-1900198 -4549849 1899841 4550234
-3950201 -1499852 3949887 1500177
-3950200 -1499852 3949882 1500180
...

result:

ok 1000 cases

Test #13:

score: -100
Time Limit Exceeded

input:

1000
100
422 747
339 -719
-600 -376
-226 79
244 6
879 -891
-63 717
403 809
259 -940
254 -26
135 -309
-517 -308
-479 -859
-270 484
292 -744
696 870
957 45
144 288
608 -601
176 350
709 951
831 281
-925 -791
277 -923
-956 692
142 652
491 398
942 -524
155 -46
341 540
978 -552
465 707
-316 36
-509 45
77 ...

output:

99999973 -19 -100000025 -22
-44100483 -83400854 44100407 83400812
-44100481 -83400864 44100405 83400811
-30300756 -66700803 30299849 66700532
-30300750 -66700804 30299856 66700531
51250873 -71300886 -51250142 71300537
76050878 -73050889 -76050648 73050567
76050879 -73050895 -76050637 73050575
500086...

result: