QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#417082#7906. Almost ConvexLeonardWA 397ms35800kbC++203.2kb2024-05-22 14:07:152024-05-22 14:08:01

Judging History

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

  • [2024-05-22 14:08:01]
  • 评测
  • 测评结果:WA
  • 用时:397ms
  • 内存:35800kb
  • [2024-05-22 14:07:15]
  • 提交

answer

#include <bits/stdc++.h>
using namespace std;
typedef pair<int, int> PII;
const int N = 2010;
struct Point { 
	double x, y; 
	int id;
	bool operator< (const Point& r){
		if(x != r.x) return x < r.x;
		else return y < r.y;
	}
};        // 点
using Vec = Point;                    // 向量
struct Line { Point P; Vec v; };      // 直线(点向式)
struct Seg { Point A, B; };           // 线段(存两个端点)
struct Circle { Point O; double r; }; // 圆(存圆心和半径)
Point a[N];
using Points = vector<Point>;
const Point O = {0, 0};                        // 原点
const Line Ox = {O, {1, 0}}, Oy = {O, {0, 1}}; // 坐标轴
const double PI = acos(-1), EPS = 1e-9;
bool eq(double a, double b) { return abs(a - b) < EPS; } // ==
bool gt(double a, double b) { return a - b > EPS; }      // >
bool lt(double a, double b) { return a - b < -EPS; }     // <
bool ge(double a, double b) { return a - b > -EPS; }     // >=
bool le(double a, double b) { return a - b < EPS; }      // <=
Vec operator+(Vec u, Vec v) { return {u.x + v.x, u.y + v.y}; }   // 向量加向量
Vec operator-(Vec u, Vec v) { return {u.x - v.x, u.y - v.y}; }   // 向量减向量
Vec operator*(double k, Vec v) { return {k * v.x, k * v.y}; }    // 数乘
double operator*(Vec u, Vec v) { return u.x * v.x + u.y * v.y; } // 点乘
double cross(Vec u, Vec v) { return u.x * v.y - u.y * v.x; } // 叉乘
bool check(Point p, Point q, Point r) // 检查三个点组成的两个向量的旋转方向是否为逆时针
{
    return lt(0, cross(q - p, r - q));
}
Points chull(Points &ps)
{
    sort(ps.begin(), ps.end());
    vector<int> I{0}, used(ps.size());
    for (int i = 1; i < ps.size(); i++)
    {
        while (I.size() > 1 && !check(ps[I[I.size() - 2]], ps[I.back()], ps[i]))
            used[I.back()] = 0, I.pop_back();
        used[i] = 1, I.push_back(i);
    }
    for (int i = ps.size() - 2; i >= 0; i--)
    {
        if (used[i])
            continue;
        while (I.size() > 1 && !check(ps[I[I.size() - 2]], ps[I.back()], ps[i]))
            I.pop_back();
        I.push_back(i);
    }
    Points H;
    for (int i = 0; i < I.size() - 1; i++)
        H.push_back(ps[I[i]]);
    return H;
}

double the[2010][2010];
double theta(auto p) { return atan2(p.y, p.x); } // 求极角
void psort(Points &ps, Point c = O)              // 极角排序
{
    sort(ps.begin(), ps.end(), [&](auto p1, auto p2) {
        return lt(the[p1.id][c.id], the[p2.id][c.id]);
    });
}
int n, st[N];
Points v, v1;
int main(){
	cin >> n;
	for(int i=1;i<=n;i++){
		cin >> a[i].x >> a[i].y;
		a[i].id = i;
		v1.push_back(a[i]);
	}
    for(int i = 1; i <= n; i++) {
        for(int j = 1; j <= n; j++) {
            the[i][j] = theta(a[i] - a[j]);
        }
    }
	v = chull(v1);
	for(int i = 0; i < v.size(); i++) st[v[i].id] = 1;
	//for(int i=0;i<v.size;i++) cout << v[i].id;
	int ans = 0;
	for(int i=1;i<=n;i++){
		if(!st[i]){
			Points tmp;
			for(int j=1;j<=n;j++){
				if(j == i) continue;
				tmp.push_back(a[j]);
			}
			psort(tmp, a[i]);
			for(int j=0;j<tmp.size()-1;j++){
				if(st[tmp[j].id] && st[tmp[j+1].id]) ans++;
			}
			if(st[tmp[0].id] && st[tmp[tmp.size()-1].id]) ans++;
		}
	}
	cout << ans + 1 << endl;
	return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 1ms
memory: 4040kb

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

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

input:

3
0 0
3 0
0 3

output:

1

result:

ok 1 number(s): "1"

Test #4:

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

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

input:

4
0 0
0 3
3 0
3 3

output:

1

result:

ok 1 number(s): "1"

Test #6:

score: 0
Accepted
time: 363ms
memory: 35516kb

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:

718

result:

ok 1 number(s): "718"

Test #7:

score: 0
Accepted
time: 391ms
memory: 35512kb

input:

2000
571314 -128802
-57762 485216
-713276 485201
-385009 -844644
371507 403789
338703 -272265
-913641 438001
-792118 -481524
709494 213762
-913577 432978
-397111 709021
840950 328210
-843628 452653
-20721 126607
-107804 -338102
930109 -89787
-949115 -76479
-862141 455623
991761 94852
-635475 625573
...

output:

658

result:

ok 1 number(s): "658"

Test #8:

score: 0
Accepted
time: 389ms
memory: 35496kb

input:

2000
-510540 -289561
-602648 -189950
-403224 944455
-369582 -41334
358122 -598933
-817147 470207
-440180 -735160
-705634 61719
319062 897001
-905089 -755682
-408371 -520115
-423336 548115
-590242 835990
208155 883477
-202087 142035
-71545 411206
570690 -673204
-228451 -903435
-732876 -570271
-246755...

output:

309

result:

ok 1 number(s): "309"

Test #9:

score: 0
Accepted
time: 394ms
memory: 35696kb

input:

2000
-532115 566389
138405 49337
398814 -97324
116833 113216
381728 877609
222402 641022
109920 952381
-113880 395181
13780 -572931
-676608 605202
-74328 -503839
-207767 926500
-663270 -146303
197877 280349
275865 -663892
-630214 3286
973786 304855
-493735 841584
394901 -505975
757960 204724
-373328...

output:

239

result:

ok 1 number(s): "239"

Test #10:

score: 0
Accepted
time: 381ms
memory: 35588kb

input:

2000
512636 509804
-661126 -592269
755566 -721837
-878213 441853
-236050 -89069
-181220 155656
203391 691764
940154 260513
747075 373881
620423 840991
-409624 335472
270937 -710659
-751290 -673585
250341 -193243
-250535 618887
-739996 543936
-547741 -213681
-82920 -364319
-611672 737719
930798 46731...

output:

1025

result:

ok 1 number(s): "1025"

Test #11:

score: 0
Accepted
time: 393ms
memory: 35496kb

input:

2000
943353 817289
237151 899722
682851 -464873
854225 205354
834550 257948
-260874 298196
-224572 -269157
-667301 881130
-45920 -696359
-634337 792620
-408527 -947513
582880 172669
921645 839423
833813 721080
-836662 -287230
-55783 -408594
108996 -122012
365647 -789544
313812 833502
970009 -737736
...

output:

218

result:

ok 1 number(s): "218"

Test #12:

score: 0
Accepted
time: 377ms
memory: 35516kb

input:

2000
619248 227987
-252490 -553032
148050 -479727
-333707 -591482
-40488 -503144
561909 255624
-402541 -798967
-245811 -610006
-146584 -517935
226433 -92580
-81939 -828480
72540 -845547
502613 220323
66708 -573015
601886 258752
406443 257854
232970 -671600
-37023 -683767
602339 456757
-440096 -71899...

output:

7

result:

ok 1 number(s): "7"

Test #13:

score: 0
Accepted
time: 397ms
memory: 35568kb

input:

2000
-602451 2956
85982 141739
-185932 -208897
-716095 58215
-468047 155612
-791626 -3105
75700 -484098
609608 -304849
689485 -106857
533177 -285261
-659400 -241162
-369302 165482
406663 265940
-353843 -788313
805885 -75440
-571955 -60471
351360 -81373
-510926 -59456
591713 179588
534794 -118
201630...

output:

66

result:

ok 1 number(s): "66"

Test #14:

score: 0
Accepted
time: 392ms
memory: 35496kb

input:

2000
41203 -675424
-158994 366628
-133859 -595680
435466 687630
687811 -35017
314337 133049
-384711 444777
54850 -760922
526166 282618
572292 94793
-324003 621393
-30308 242225
612969 -231837
-56628 -892609
-492077 58749
29597 -349591
198510 219502
380955 -59845
839171 -40068
88185 -820614
-572977 -...

output:

43

result:

ok 1 number(s): "43"

Test #15:

score: 0
Accepted
time: 388ms
memory: 35644kb

input:

2000
-814040 46114
-324077 -522697
388552 -604274
-252898 43028
-757069 141507
413462 -649779
-281915 -316285
-498931 -573214
-408766 670792
-271435 -393170
87187 731739
89312 -853584
-768680 -307261
-185324 234729
-70493 -354866
16452 164338
-650791 -518077
851196 -259322
-85395 -509349
241593 5074...

output:

129

result:

ok 1 number(s): "129"

Test #16:

score: 0
Accepted
time: 385ms
memory: 35572kb

input:

2000
23103 -796677
-148322 67634
-525131 -446626
2672 584671
-712789 -69579
-91150 -429393
-375635 -487235
-680553 -370975
793181 -383683
-234131 -462420
-734705 -171834
322671 -355011
760005 224249
700248 -352775
416862 -125857
-497951 717254
677084 -451876
-220123 616240
525973 -144881
-300828 553...

output:

1466

result:

ok 1 number(s): "1466"

Test #17:

score: 0
Accepted
time: 388ms
memory: 35556kb

input:

2000
-185174 470373
-772343 -70370
-182314 851727
661615 -250979
-581175 527646
332025 141502
-659052 -506788
-378459 -553180
11233 162287
469975 -572356
679074 217029
-137967 727723
581696 140544
452574 -319370
120895 129820
772655 -330960
122860 823902
-786221 147543
-206152 -373647
-212943 4820
6...

output:

2801

result:

ok 1 number(s): "2801"

Test #18:

score: 0
Accepted
time: 379ms
memory: 35708kb

input:

2000
-718158 695879
655921 595312
-509080 -860718
540612 244159
-83221 -865654
-460513 -542465
102321 -775593
328552 799263
-284269 -725108
152140 549502
-108610 465054
-97837 -449762
-772869 -171472
293831 -711723
508617 -157976
170737 323070
544222 385453
-633043 -233165
-620164 -459706
507218 338...

output:

14445

result:

ok 1 number(s): "14445"

Test #19:

score: 0
Accepted
time: 382ms
memory: 35732kb

input:

2000
-587991 -165467
-530325 -5525
-574943 180654
-496535 -748102
-436469 -160646
110285 237070
-822862 -141480
-177189 327799
-424868 331309
-999274 38095
-745710 192605
-234174 -804258
586432 -176239
-626756 499109
-562606 826724
890245 455480
-32262 -298900
550800 516690
-588632 -368654
405331 -3...

output:

64358

result:

ok 1 number(s): "64358"

Test #20:

score: 0
Accepted
time: 334ms
memory: 35800kb

input:

2000
441575 -414673
651578 -449237
287355 -489950
606811 -30288
-733692 679481
-652568 89883
-360110 616801
190405 -368787
-352383 935855
118240 73038
-374899 -927065
-22183 -491455
-146229 638417
998825 -48442
-374469 243261
988830 149043
-778607 -291542
-277026 -167975
372912 -405043
535321 425727...

output:

233885

result:

ok 1 number(s): "233885"

Test #21:

score: 0
Accepted
time: 284ms
memory: 35588kb

input:

2000
-369265 -366669
-225059 -65255
750236 -107534
-252341 967638
533029 -79205
-482639 504243
-164616 -477455
-219649 975578
222020 297565
-548636 -836060
595498 -345235
-971961 -235140
179392 983777
747498 664263
-458850 -513884
-456639 186799
508542 -359953
630300 5257
-294961 -599723
999627 2729...

output:

430546

result:

ok 1 number(s): "430546"

Test #22:

score: 0
Accepted
time: 282ms
memory: 35716kb

input:

2000
-586906 -809654
-279647 960102
-279925 501031
-76716 526333
-277891 -599253
171606 -289251
565124 -825005
-125381 -163097
-71257 -202933
999551 29949
286017 -698748
257733 358898
6047 18648
283230 -959051
221238 -975219
686818 32684
368089 -929790
-689242 449329
-547431 836850
612952 -790120
-9...

output:

484966

result:

ok 1 number(s): "484966"

Test #23:

score: 0
Accepted
time: 277ms
memory: 35724kb

input:

2000
-360385 -932803
6402 -568575
477942 -878390
361387 -497256
-383874 -126116
-838786 214745
157834 -987465
955879 293759
-91170 -521309
262250 964999
883045 -469287
350745 823160
999731 -23179
-791215 8792
208002 153508
-553609 549966
-345358 591962
-613852 198594
81698 996657
803702 98789
201163...

output:

513300

result:

ok 1 number(s): "513300"

Test #24:

score: 0
Accepted
time: 255ms
memory: 35452kb

input:

2000
-996201 87077
834777 -550587
-316381 948632
750921 -473436
-170208 -985408
-98642 17818
735787 -677212
80294 -996771
-420703 594219
995302 -96813
997685 68003
-680287 396657
-986559 163401
313494 442433
-774277 632845
809816 -586683
-569560 692991
956486 -291775
992620 -121264
998004 -63141
-64...

output:

528222

result:

ok 1 number(s): "528222"

Test #25:

score: -100
Wrong Answer
time: 270ms
memory: 35652kb

input:

2000
-876642 481141
513009 -76454
48555 998820
-665181 11267
-681766 -551841
-724328 30683
-594565 -308913
799027 -601295
390878 658489
300660 953731
-227699 973731
621281 283696
871533 490336
-363638 931539
592572 805516
330089 201429
-282723 -959201
-351348 316419
-5935 -999982
-413615 -910451
-14...

output:

527977

result:

wrong answer 1st numbers differ - expected: '527976', found: '527977'