QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#830708 | #868. Friendship Circles | Calculatelove | AC ✓ | 36ms | 12600kb | C++14 | 2.8kb | 2024-12-24 21:55:54 | 2024-12-24 21:56:01 |
Judging History
answer
#include <bits/stdc++.h>
const int N = 100100;
const double inf = 1e18;
const double eps = 1e-7;
int sgn(double n) {
if (fabs(n) < eps) return 0;
return n > 0 ? +1 : -1;
}
int dcmp(double x, double y) {
return sgn(x - y);
}
struct point {
double x, y;
point() { x = y = 0; }
point(double _x, double _y) : x(_x), y(_y) {}
void input() {
scanf("%lf%lf", &x, &y);
}
};
typedef point vec;
vec operator + (vec a, vec b) { return vec(a.x + b.x, a.y + b.y); }
vec operator - (vec a, vec b) { return vec(a.x - b.x, a.y - b.y); }
vec operator * (vec a, double b) { return vec(a.x * b, a.y * b); }
double cross(vec a, vec b) {
return a.x * b.y - a.y * b.x;
}
double area(vec a, vec b, vec c) {
return cross(b - a, c - a);
}
double get_angle(vec a) {
return atan2(a.y, a.x);
}
struct line {
point st, ed;
double ag;
int id;
line() {}
line(point A, point B) : st(A), ed(B), ag(get_angle(B - A)) {}
};
point line_intersection(line A, line B) {
point p = A.st, q = B.st;
vec x = A.ed - A.st, y = B.ed - B.st;
vec u = q - p;
double t = cross(u, y) / cross(x, y);
return p + x * t;
}
bool ruler(line a, line b) {
double x = a.ag, y = b.ag;
if (!dcmp(x, y)) return sgn(area(a.st, a.ed, b.ed)) < 0;
return x < y;
}
bool on_right(point x, line c) {
return sgn(area(c.st, c.ed, x)) < 0;
}
int n;
point p[N];
line a[N];
point g[N];
int l, r;
int q[N];
void plane_intersection() {
std::sort(a + 1, a + 1 + n, ruler);
l = 1, r = 0;
for (int i = 1; i <= n; i ++) {
if (i > 1 && !dcmp(a[i].ag, a[i - 1].ag)) continue;
while (l < r && on_right(g[r - 1], a[i])) r --;
while (l < r && on_right(g[l], a[i])) l ++;
q[++ r] = i;
if (l < r) g[r - 1] = line_intersection(a[q[r - 1]], a[q[r]]);
}
while (l < r - 1 && on_right(g[r - 1], a[q[l]])) r --;
}
void work() {
scanf("%d", &n), n --;
for (int i = 0; i <= n; i ++) p[i].input();
for (int i = 1; i <= n; i ++) {
point mid = point((p[i].x + p[0].x) / 2.0, (p[i].y + p[0].y) / 2.0);
vec dir = vec(-(p[i].y - p[0].y), (p[i].x - p[0].x));
a[i] = line(mid, mid + dir), a[i].id = i;
}
a[++ n] = line(point(+inf, +inf), point(-inf, +inf)), a[n].id = 0;
a[++ n] = line(point(-inf, +inf), point(-inf, -inf)), a[n].id = 0;
a[++ n] = line(point(-inf, -inf), point(+inf, -inf)), a[n].id = 0;
a[++ n] = line(point(+inf, -inf), point(+inf, +inf)), a[n].id = 0;
plane_intersection();
std::vector<int> ans; ans.clear();
for (int i = l; i <= r; i ++)
if (a[q[i]].id > 0) ans.push_back(a[q[i]].id);
std::sort(ans.begin(), ans.end());
printf("%d ", (int)ans.size());
for (int x : ans) printf("%d ", x);
puts("");
}
int main() {
int T;
scanf("%d", &T);
while (T --)
work();
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 2ms
memory: 12060kb
input:
2 4 1 0 3 1 3 -2 7 0 5 0 0 -2 -1 2 2 -2 10 -1 11
output:
2 1 2 3 1 2 3
result:
ok 7 numbers
Test #2:
score: 0
Accepted
time: 23ms
memory: 12048kb
input:
10000 10 132243110 -894263225 -965927366 756806080 -563126858 -401644076 -528090722 -199265042 -184232391 -184423675 -346777300 -583114791 624815460 788278140 543172921 980159251 -143672624 674688477 -393343296 525780596 9 64745555 827730910 -665070184 -152609349 -905275127 -345568169 -949821348 -84...
output:
3 4 5 6 5 1 4 6 7 8 1 1 3 1 2 3 2 2 5 3 1 2 3 6 1 2 3 4 5 6 5 1 2 3 4 9 4 1 2 3 4 6 1 2 3 4 5 9 2 1 2 3 1 4 6 5 2 4 5 6 7 4 1 2 4 5 3 1 2 3 4 1 2 3 6 3 1 6 8 1 1 2 1 2 5 1 3 4 6 7 5 1 2 4 5 6 3 2 3 4 4 1 3 4 7 4 1 3 7 9 3 3 4 5 4 3 4 6 8 5 1 3 4 6 7 3 1 2 3 2 2 3 3 2 5 6...
result:
ok 41282 numbers
Test #3:
score: 0
Accepted
time: 14ms
memory: 12204kb
input:
1000 53 981976744 508887295 -580496145 -368111494 -40659809 382477779 847997458 -445652992 -709716808 -129570248 -313838973 349710333 -876139130 111370588 320646104 -950965389 548578750 -574361293 -799802872 957309031 127037627 -53366027 -477625360 229044322 -283654405 965960603 -83080242 -489998095...
output:
4 34 40 41 47 6 9 14 19 27 32 67 5 30 37 44 46 48 5 20 27 29 30 38 6 8 11 13 18 23 43 4 5 10 13 89 7 17 26 32 52 70 72 80 5 1 2 3 4 5 4 31 52 57 66 7 9 10 14 16 21 26 27 7 1 5 6 8 9 10 11 8 9 21 22 24 26 27 33 37 7 7 9 28 35 54 55 65 4 14 26 30 62 4 1 2 8 11 6 8 14 36 48 51 76 4 14 1...
result:
ok 6180 numbers
Test #4:
score: 0
Accepted
time: 31ms
memory: 12276kb
input:
100 1000 154123590 -195643584 906998887 659267250 -861981209 -248731154 156410684 -366976998 636150181 849111460 212242101 726773347 -441502446 718696955 -726340230 -438559100 523592711 -829247123 -429817421 -907222370 -743602659 503290332 48678284 954678898 819529524 103315724 -803643464 249247717 ...
output:
5 231 574 863 946 983 5 95 148 373 491 578 6 266 533 717 724 732 829 8 8 26 126 416 647 733 734 831 7 209 630 680 725 926 931 980 7 46 203 385 572 759 798 992 5 234 267 322 395 722 5 234 589 597 724 802 7 77 286 508 527 578 629 949 5 210 754 778 829 933 7 76 214 299 300 746 935 951 6 468 ...
result:
ok 706 numbers
Test #5:
score: 0
Accepted
time: 12ms
memory: 12144kb
input:
50 1000 585441498 537521779 -299019164 -926606017 955725480 -237915475 -999645057 192074481 -543154139 -494983865 -509026736 837773604 548176004 89171630 -985096027 659257966 -821797427 -327883708 571023968 785197466 -650635428 138842844 -81541899 267997223 -369325984 38167872 541905647 -15789881 -3...
output:
6 268 310 339 486 653 770 5 211 282 365 411 636 5 123 209 472 585 766 5 254 393 425 798 927 6 210 570 578 641 908 928 6 129 154 513 717 812 933 6 172 377 476 518 532 716 5 143 417 442 754 888 7 107 145 188 390 567 643 710 8 40 367 386 430 508 694 872 901 5 13 62 335 508 750 4 55 378 408 4...
result:
ok 339 numbers
Test #6:
score: 0
Accepted
time: 4ms
memory: 12144kb
input:
20 1000 949240525 985538611 750623973 -891600358 486266434 -795975822 590585910 -31981534 -330952737 -267486074 161784968 -322523021 570490959 -530866569 -87914744 -576652443 -220687519 -57167345 679521862 -251619499 -274604922 -966571426 -225598794 395382053 779474773 -750165705 -52945103 180963514...
output:
6 116 178 389 511 847 863 6 41 218 430 668 804 951 5 520 526 575 818 914 6 100 127 329 412 551 597 5 50 131 256 361 978 9 47 57 383 446 464 523 584 605 683 5 50 77 488 637 998 7 86 186 208 230 364 639 842 5 87 237 383 590 907 4 229 844 870 979 5 99 509 571 760 945 6 101 108 174 571 681 91...
result:
ok 136 numbers
Test #7:
score: 0
Accepted
time: 8ms
memory: 11952kb
input:
20 1000 -167643347 854054751 -950562769 839061824 -534384313 748502955 -829385211 -983764842 744757226 14818109 -309178784 439036722 -196741654 -211072840 -425752933 -499204526 207784396 947337110 847919880 892677446 -982316981 -346423648 -855715476 -942552076 801788630 -174822793 660149118 76138837...
output:
6 227 232 391 636 754 979 6 229 291 542 673 683 944 5 145 279 435 982 997 5 90 279 338 368 567 4 1 279 387 953 7 54 189 281 466 633 919 955 6 112 206 559 683 897 935 6 17 399 853 938 939 968 7 164 232 535 584 629 651 762 9 19 294 331 417 461 654 770 918 919 8 211 401 419 444 571 613 682 95...
result:
ok 146 numbers
Test #8:
score: 0
Accepted
time: 8ms
memory: 12172kb
input:
20 1000 -989559922 -717620596 788441976 9915493 -700259251 292981732 900386772 654386442 965691382 297122291 70114359 55372274 -404165756 373562106 -498749906 723467583 -508967882 -898415332 426383307 331941687 869779472 273724130 -340607967 279322308 529135191 695487416 -626756661 192070132 3863746...
output:
4 182 471 575 904 6 105 212 248 352 535 679 8 50 307 386 464 547 652 909 952 7 27 180 288 485 821 892 962 6 48 297 437 465 782 876 8 17 81 167 409 438 818 918 930 5 267 363 409 808 926 7 157 249 471 659 662 663 941 6 209 276 547 624 914 926 6 212 235 436 447 651 964 5 54 285 444 455 517 4...
result:
ok 140 numbers
Test #9:
score: 0
Accepted
time: 4ms
memory: 12060kb
input:
20 1000 188523502 855928248 -617777470 35544971 279090002 -722348004 630158756 -297396866 891658241 579426473 744374799 -888100686 238667038 693355835 -836588095 505948204 -375463263 106089122 594781325 331014439 721875924 -251352284 174499542 -203836013 551449048 420573432 381304856 -932537711 -440...
output:
7 189 303 443 746 781 871 994 4 218 623 820 902 5 60 476 828 830 894 7 177 274 406 441 443 553 798 5 123 261 428 610 735 6 86 334 443 532 631 846 6 203 360 503 526 582 707 8 127 162 449 678 684 742 834 993 6 171 184 227 521 561 780 6 103 164 264 407 610 670 8 104 112 157 165 174 558 714 76...
result:
ok 143 numbers
Test #10:
score: 0
Accepted
time: 12ms
memory: 12048kb
input:
10 9172 912539639 -412602596 -170683029 -339514159 240423405 682241967 -908332244 -739591132 49189079 245180429 804822663 -237424332 41789403 -94091238 485092068 920876789 -78296892 313466107 964497553 -653082143 385178750 -111453794 -446173892 688484468 -25448547 -246188240 -995961733 -332340305 87...
output:
6 167 2692 3047 6627 6672 8899 5 102 116 149 164 246 7 15 33 57 65 72 84 117 8 791 1421 2972 3641 4168 7769 7781 9159 6 520 917 1123 1445 2028 2378 5 14 1278 2039 2132 2134 8 1760 2053 2143 2198 4090 5070 5152 5491 6 2 5 7 21 29 190 5 203 415 2511 4767 5208 6 536 4092 4527 5721 7536 7759
result:
ok 72 numbers
Test #11:
score: 0
Accepted
time: 15ms
memory: 12268kb
input:
1 51976 218479545 -323200417 138714781 -709381932 -462379498 450920276 -307976979 426884097 -520439495 892377325 -914912579 -171317468 -862054514 -623904272 -933747975 -562729385 -669135197 -807350552 760790512 -527095882 738243496 -806739291 -377065000 -514514972 -219081738 72062649 648396616 -8346...
output:
4 5729 17362 23622 42866
result:
ok 5 number(s): "4 5729 17362 23622 42866"
Test #12:
score: 0
Accepted
time: 11ms
memory: 12192kb
input:
1 39560 86995686 270580137 459311555 564934617 522290767 180692260 -114536095 -792373236 56831984 126446276 -153352835 766482623 -542260784 -696901245 -856300058 720518338 630336553 -638952534 -945169439 765192059 -936576022 -291631782 844809383 -492201115 -493995722 785156870 933854180 43810956 707...
output:
5 69 9765 13467 22962 39047
result:
ok 6 numbers
Test #13:
score: 0
Accepted
time: 14ms
memory: 11952kb
input:
1 47636 -339455470 864360691 189973737 -455716129 -228197753 -89535757 -771352107 -866406376 44168870 800706716 -537017283 854025817 337341457 965260566 -778852141 -851009748 489616815 939510892 -95839790 912255808 -316428244 518443023 361651062 -469887258 376314486 -501748908 -485720959 362492564 8...
output:
5 12279 15431 28553 37024 44937
result:
ok 6 numbers
Test #14:
score: 0
Accepted
time: 13ms
memory: 12076kb
input:
1 35220 -765906626 308398140 -639172594 -621591067 -683718976 785460418 866799177 -645472221 326473052 -230065548 519509756 -503141389 362167890 892263593 443819968 432237974 -210911435 -892091090 -656575549 -940680444 -841504658 -406640955 -416474555 -742540697 -753375305 211345313 -465104610 91239...
output:
5 431 5596 18791 22640 34886
result:
ok 6 numbers
Test #15:
score: 0
Accepted
time: 10ms
memory: 12088kb
input:
1 33050 -897390485 607211398 -908510412 357758186 300951289 220265106 -84984131 -719505361 903744531 149227595 -718930500 434658701 -758229869 554425404 521267885 -284514303 -56663876 981339632 -362535501 911416009 -221356881 108466554 245591317 -720226840 -472999689 -780593170 -179647045 969729701 ...
output:
6 2785 7705 16069 18056 21113 28584
result:
ok 7 numbers
Test #16:
score: 0
Accepted
time: 8ms
memory: 11980kb
input:
1 20634 -764033129 346216144 -882880935 -662892560 -154569934 -609771423 -741800143 -498571206 -813951287 823488035 337596540 -627541208 -438436139 776395727 303748506 -445976981 -757192126 -850262350 781761444 203703949 398790897 623574063 -532534300 -697912983 -747913673 -67498949 -453997992 -7115...
output:
6 1794 2579 11159 11783 18267 20116
result:
ok 7 numbers
Test #17:
score: 0
Accepted
time: 35ms
memory: 11984kb
input:
1 100000 -646797560 218479545 -323200417 138714781 -709381932 -462379498 450920276 -307976979 426884097 -520439495 892377325 -914912579 -171317468 -862054514 -623904272 -933747975 -562729385 -669135197 -807350552 760790512 -527095882 738243496 -806739291 -377065000 -514514972 -219081738 72062649 648...
output:
5 37026 53371 56617 66977 78931
result:
ok 6 numbers
Test #18:
score: 0
Accepted
time: 31ms
memory: 11984kb
input:
1 100000 236318568 86995686 270580137 459311555 564934617 522290767 180692260 -114536095 -792373236 56831984 126446276 -153352835 766482623 -542260784 -696901245 -856300058 720518338 630336553 -638952534 -945169439 765192059 -936576022 -291631782 844809383 -492201115 -493995722 785156870 933854180 4...
output:
7 6732 15569 33589 38485 70033 72318 90876
result:
ok 8 numbers
Test #19:
score: 0
Accepted
time: 36ms
memory: 12248kb
input:
1 100000 -290630712 -339455470 864360691 189973737 -455716129 -228197753 -89535757 -771352107 -866406376 44168870 800706716 -537017283 854025817 337341457 965260566 -778852141 -851009748 489616815 939510892 -95839790 912255808 -316428244 518443023 361651062 -469887258 376314486 -501748908 -485720959...
output:
6 35537 41042 47921 53983 77048 82612
result:
ok 7 numbers
Test #20:
score: 0
Accepted
time: 35ms
memory: 12012kb
input:
1 100000 592485416 -765906626 308398140 -639172594 -621591067 -683718976 785460418 866799177 -645472221 326473052 -230065548 519509756 -503141389 362167890 892263593 443819968 432237974 -210911435 -892091090 -656575549 -940680444 -841504658 -406640955 -416474555 -742540697 -753375305 211345313 -4651...
output:
8 11280 18791 26082 33626 39077 39842 54691 77606
result:
ok 9 numbers
Test #21:
score: 0
Accepted
time: 31ms
memory: 12228kb
input:
1 100000 -229431160 -897390485 607211398 -908510412 357758186 300951289 220265106 -84984131 -719505361 903744531 149227595 -718930500 434658701 -758229869 554425404 521267885 -284514303 -56663876 981339632 -362535501 911416009 -221356881 108466554 245591317 -720226840 -472999689 -780593170 -17964704...
output:
5 9509 13914 25880 27743 78913
result:
ok 6 numbers
Test #22:
score: 0
Accepted
time: 36ms
memory: 12132kb
input:
1 100000 653684968 -764033129 346216144 -882880935 -662892560 -154569934 -609771423 -741800143 -498571206 -813951287 823488035 337596540 -627541208 -438436139 776395727 303748506 -445976981 -757192126 -850262350 781761444 203703949 398790897 623574063 -532534300 -697912983 -747913673 -67498949 -4539...
output:
4 11518 18915 86428 93084
result:
ok 5 number(s): "4 11518 18915 86428 93084"
Test #23:
score: 0
Accepted
time: 2ms
memory: 12068kb
input:
1 100 0 0 1000000000 0 998369103 57088810 993481735 113991409 985353835 170522192 974011916 226496767 959492973 281732556 941844363 336049393 921123653 389270106 897398428 441221101 870746077 491732924 841253532 540640817 809016994 587785252 774141610 633012453 736741137 676174900 696937568 71713180...
output:
99 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99
result:
ok 100 numbers
Test #24:
score: 0
Accepted
time: 2ms
memory: 12152kb
input:
1 1000 0 0 1000000000 0 999980649 6220935 999922599 12441630 999825852 18661843 999690411 24881334 999516282 31099862 999303471 37317186 999051986 43533067 998761838 49747262 998433037 55959532 998065597 62169637 997659531 68377336 997214855 74582388 996731586 80784554 996209744 86983594 995649347 9...
output:
999 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 ...
result:
ok 1000 numbers
Test #25:
score: 0
Accepted
time: 5ms
memory: 12208kb
input:
1 10000 0 0 1000000000 0 999999803 627690 999999212 1255381 999998227 1883071 999996848 2510760 999995075 3138449 999992908 3766136 999990347 4393821 999987392 5021505 999984043 5649187 999980300 6276867 999976163 6904544 999971632 7532218 999966707 8159890 999961388 8787558 999955675 9415223 999949...
output:
9999 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101...
result:
ok 10000 numbers
Test #26:
score: 0
Accepted
time: 32ms
memory: 12600kb
input:
1 100000 0 0 1000000000 0 999999998 62825 999999992 125651 999999982 188476 999999968 251302 999999950 314127 999999928 376953 999999903 439778 999999873 502604 999999840 565430 999999802 628255 999999761 691081 999999715 753906 999999666 816732 999999613 879557 999999555 942383 999999494 1005208 99...
output:
99999 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 10...
result:
ok 100000 numbers