Skip to content

Commit bc578b1

Browse files
authored
Merge pull request #1354 from tatesoto/fix/minimum_enclosing_circle
テストケース修正 Minimum Enclosing Circle
2 parents b9608f7 + a98afa0 commit bc578b1

3 files changed

Lines changed: 52 additions & 41 deletions

File tree

geo/minimum_enclosing_circle/gen/max_circle.cpp

Lines changed: 13 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -22,8 +22,6 @@ void out(set<P> S) {
2222
for (auto& [x, y]: V) { printf("%d %d\n", x, y); }
2323
}
2424

25-
const long double PI = acosl(-1.0L);
26-
2725
int main(int, char* argv[]) {
2826
long long seed = atoll(argv[1]);
2927
auto gen = Random(seed);
@@ -32,23 +30,24 @@ int main(int, char* argv[]) {
3230

3331
int n = N_MAX;
3432
int r = X_AND_Y_ABS_MAX;
35-
for (int i = 0; i < n; i++) {
36-
long double theta = (long double)(i) * 2 * PI / (long double)(n);
37-
long double ldx = r * cos(theta);
38-
long double ldy = r * sin(theta);
39-
int x = (int)(ldx);
40-
int y = (int)(ldy);
41-
while (y > 0 && x*x + (y+1)*(y+1) <= r*r) y++;
42-
while (y < 0 && x*x + (y-1)*(y-1) <= r*r) y--;
43-
if (abs(x) > X_AND_Y_ABS_MAX) x = (x < 0 ? -X_AND_Y_ABS_MAX : X_AND_Y_ABS_MAX);
44-
if (abs(y) > X_AND_Y_ABS_MAX) y = (y < 0 ? -X_AND_Y_ABS_MAX : X_AND_Y_ABS_MAX);
33+
int x = 0, y = r;
34+
S.insert({x, y});
35+
S.insert({x, -y});
36+
while (x < r) {
37+
x++;
38+
while (y > 0 && x*x + y*y > r*r) y--;
4539
S.insert({x, y});
40+
S.insert({-x, y});
41+
S.insert({x, -y});
42+
S.insert({-x, -y});
4643
}
4744

48-
int LIM = X_AND_Y_ABS_MAX*7/10;
45+
int LIM = X_AND_Y_ABS_MAX;
4946
while (int(S.size()) < n) {
5047
P p = random_point(gen, LIM);
51-
S.insert(p);
48+
if (p.first * p.first + p.second * p.second <= r * r) {
49+
S.insert(p);
50+
}
5251
}
5352

5453
out(S);

geo/minimum_enclosing_circle/gen/near_circle.cpp

Lines changed: 31 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -37,8 +37,6 @@ void out(set<P> S, bool shuffle) {
3737
for (auto& [x, y]: V) { printf("%d %d\n", x, y); }
3838
}
3939

40-
const long double PI = acosl(-1.0L);
41-
4240
int main(int, char* argv[]) {
4341
long long seed = atoll(argv[1]);
4442
auto gen = Random(seed);
@@ -48,24 +46,38 @@ int main(int, char* argv[]) {
4846
int LIM = lims[seed % 2];
4947

5048
set<P> S;
51-
52-
int n = gen.uniform<int>(100, N_MAX);
53-
int r = gen.uniform<int>(LIM/2, LIM*3/4);
54-
long double phi = gen.uniform<double>(0, 2 * PI);
55-
for (int i = 0; i < n; i++) {
56-
long double theta = (long double)(i) * 2 * PI / (long double)(n) + phi;
57-
long double ldx = r * cos(theta);
58-
long double ldy = r * sin(theta);
59-
int x = (int)(ldx);
60-
int y = (int)(ldy);
61-
while (y > 0 && x*x + (y+1)*(y+1) <= r*r) y++;
62-
while (y < 0 && x*x + (y-1)*(y-1) <= r*r) y--;
63-
y += gen.uniform<int>(-1, 1);
64-
if (abs(x) > X_AND_Y_ABS_MAX) x = (x < 0 ? -X_AND_Y_ABS_MAX : X_AND_Y_ABS_MAX);
65-
if (abs(y) > X_AND_Y_ABS_MAX) y = (y < 0 ? -X_AND_Y_ABS_MAX : X_AND_Y_ABS_MAX);
66-
S.insert({(int)x, (int)y});
49+
50+
int rx = gen.uniform<int>(LIM*5/9, LIM*2/3);
51+
int ry = gen.uniform<int>(LIM*5/9, LIM*2/3);
52+
int r_sq = rx*rx + ry*ry;
53+
int r = (int)sqrt(r_sq);
54+
int cx = gen.uniform<int>(-X_AND_Y_ABS_MAX + r*11/10, X_AND_Y_ABS_MAX - r*11/10);
55+
int cy = gen.uniform<int>(-X_AND_Y_ABS_MAX + r*11/10, X_AND_Y_ABS_MAX - r*11/10);
56+
int x = 0, y = r;
57+
S.insert({x + cx, y + cy});
58+
S.insert({x + cx, -y + cy});
59+
const int dy[] = {-1, 0, 1};
60+
while (x < r) {
61+
x++;
62+
while (y > 0 && x*x + y*y > r_sq) y--;
63+
int px = x;
64+
int py = y;
65+
for (int d = 0; d < 3; d++) {
66+
int nx = px;
67+
int ny = py + dy[d];
68+
if (abs(nx) > X_AND_Y_ABS_MAX) nx = (nx < 0 ? -X_AND_Y_ABS_MAX : X_AND_Y_ABS_MAX);
69+
if (abs(ny) > X_AND_Y_ABS_MAX) ny = (ny < 0 ? -X_AND_Y_ABS_MAX : X_AND_Y_ABS_MAX);
70+
int insert_flag = gen.uniform(0, 15);
71+
if (insert_flag & 1) S.insert({nx + cx, ny + cy});
72+
if (insert_flag & 2) S.insert({-nx + cx, ny + cy});
73+
if (insert_flag & 4) S.insert({nx + cx, -ny + cy});
74+
if (insert_flag & 8) S.insert({-nx + cx, -ny + cy});
75+
}
76+
}
77+
while (int(S.size()) > N_MAX) {
78+
auto it = S.begin();
79+
S.erase(it);
6780
}
68-
6981
bool shuffle = gen.uniform_bool();
7082
out(S, shuffle);
7183
return 0;

geo/minimum_enclosing_circle/hash.json

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -17,16 +17,16 @@
1717
"large_random_03.out": "81c742ee4102e12ffdd9b63b9d8d0c2326613ad3785a1978d2cc177083e52f22",
1818
"large_random_04.in": "e9ab7128a80ee11fc52894d978d58b81b8a7c35b9b34920f4f9eec0c71b8782a",
1919
"large_random_04.out": "35b164cffcde21334f12e2d8075cf276877116f7939297f4099e6d13702ebdd9",
20-
"max_circle_00.in": "5b5cc6eafb16c2872a687696762706d16e5f6c42e01002b5caadec44735d9d31",
21-
"max_circle_00.out": "8a1db48be12fbad3543009d5944c324030ca5552ed6217f6ca4d7822bf02a123",
20+
"max_circle_00.in": "76475f24cd17198a480f2d94824af03f13e04b42fe5b942f4d409e512250cce6",
21+
"max_circle_00.out": "dff58cc6fcfd857a37b616d30a58c9e8255c2041e32f5518ed59934c31b7b3b7",
2222
"megiddo_worst_00.in": "97990c580383ae472f9be021aa76604b04aaa1820bfb8a2785176b0fda2728d3",
2323
"megiddo_worst_00.out": "15dcb2e972546a1cd52c39c6e6154ff72d95268e62f6bb9c11f4d67b45d70574",
24-
"near_circle_00.in": "50144ba6fc29fdfa9d59ff3f0aa1d629695ca61699d06f3621363ad166cdb150",
25-
"near_circle_00.out": "dd4cc2484705cb4afa7c79894e54920d1cd4e6969c20c2cee377ddd21321a452",
26-
"near_circle_01.in": "6899d3ebdc2346373b2e617867b346d718faefcc39551e56b768ca03a3d22d2d",
27-
"near_circle_01.out": "09d8d59d94d25ffbba2a832d55fdfd9bc3ccaec6495a4d444a03f0b312278d8f",
28-
"near_circle_02.in": "1b10184b8fd12fda219b7df4681b2976c7ffa70638aafe1c7cdb13c03cb13f4c",
29-
"near_circle_02.out": "e8c959983a3512a7ee98505259bce75c8a22a5a62452b400ec5fd7e2b2ebf160",
24+
"near_circle_00.in": "6c8158e778e7dede2aae7fe85bc73d1bd1706070f2568cf93787c10f3362463e",
25+
"near_circle_00.out": "b2c2a76878411eb7832d9184e954e26611019443774ede66aa7568204f4c6ff7",
26+
"near_circle_01.in": "a8feb04c19df441cc5853e0a999f5a60d51bdf20ec70695df0240c33c1eba2e6",
27+
"near_circle_01.out": "f6d30ea1c0bdf74cd52013e7a62ef33f9cdae74fe69726684ba3d990a77310ed",
28+
"near_circle_02.in": "fa0f6aba9c9bc77291ddecccf864ce2a1216225ffb9a005e027a4809ba7c3a83",
29+
"near_circle_02.out": "62a4229f7e5b5fcd03dfdc2076a8a62961c1643b563cee37224feb6fa686900e",
3030
"near_colinear_00.in": "138a3198c0bb285c18e0a6e09dd0e7b113a2caeef57b3b47dbfc2f0f202c3601",
3131
"near_colinear_00.out": "9c598a60c3f45d74335e160532b09a87f5eb188ae2ad0660d92264bef65dea7e",
3232
"near_colinear_01.in": "fbacc00556bdc910b8b57aa428449c13c32f873b7a67a895f043c461dcb96b24",

0 commit comments

Comments
 (0)