Skip to content

Commit

Permalink
Merge pull request #1205 from maspypy/fix_near_grid
Browse files Browse the repository at this point in the history
テストケース追加(issue 1204)
  • Loading branch information
maspypy authored Jul 9, 2024
2 parents c5882e8 + 974d843 commit f4185dd
Show file tree
Hide file tree
Showing 8 changed files with 144 additions and 2 deletions.
58 changes: 58 additions & 0 deletions geo/closest_pair/gen/fix_near_grid.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
#include <cstdio>
#include <cstdlib>
#include <utility>
#include "random.h"
#include "../params.h"

using namespace std;

using P = pair<int, int>;

P random_point(Random& gen, int LIM) {
int x = gen.uniform(-LIM, LIM);
int y = gen.uniform(-LIM, LIM);
return {x, y};
}

void out(vector<vector<P>> ALL) {
int T = ALL.size();
printf("%d\n", T);
for (auto& S: ALL) {
int n = S.size();
printf("%d\n", n);
for (auto& [x, y]: S) { printf("%d %d\n", x, y); }
}
}

int main(int, char* argv[]) {
long long seed = atoll(argv[1]);
auto gen = Random(seed);

vector<vector<P>> ALL;
int n = 1;
while ((n + 1) * (n + 1) <= SUM_N_MAX) ++n;

int eps = 100;
/*
x[0],x[1],...,x[N-1]
*/
int LIM = X_AND_Y_ABS_MAX;
int d = LIM / (n - 1);

auto get = [&](int i) -> int {
int x = i * d - (LIM / 2);
return x + gen.uniform<int>(-eps, eps);
};

vector<P> S;
for (int i = 0; i < n; ++i) {
for (int j = 0; j < n; ++j) {
int x = get(i), y = get(j);
S.emplace_back(x, y);
}
}
ALL.emplace_back(S);

out(ALL);
return 0;
}
7 changes: 6 additions & 1 deletion geo/closest_pair/gen/near_grid.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,11 @@ void out(vector<vector<P>> ALL) {
}
}

/*
This code is not implemented as intended.
The correct implementation can be found in fix_near_grid.cpp.
https://github.com/yosupo06/library-checker-problems/issues/1204
*/
int main(int, char* argv[]) {
long long seed = atoll(argv[1]);
auto gen = Random(seed);
Expand All @@ -38,7 +43,7 @@ int main(int, char* argv[]) {
x[0],x[1],...,x[N-1]
*/
int LIM = X_AND_Y_ABS_MAX;
int d = LIM / (N - 1);
int d = LIM / (N - 1); // this line should be int d = LIM / (n - 1);

auto get = [&](int i) -> int {
int x = i * d - (LIM / 2);
Expand Down
4 changes: 4 additions & 0 deletions geo/closest_pair/hash.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,10 @@
"all_same_00.out": "b169bd5467675d44e355b3c9e24761ca1fb76d3344e7f460ec7538938018af8f",
"example_00.in": "dc699db01795b4f323d4ea4ae7ccbe8b060f847a340003dbfd8395ac526916c0",
"example_00.out": "647863a5d53133d680981c6ada876b1f8e5d36751c5d6f43eb1ac5a862943580",
"fix_near_grid_00.in": "624a5b8059e7b97950b042bf1776580d54edd842b193c0c27525ac443168a52c",
"fix_near_grid_00.out": "0c248e6e419bc5f502accf44920513b05d607b3e5ce754ea994fd14c60ca35f1",
"fix_near_grid_01.in": "01292b7ca2ca6cc7f4c371d8bc0160bc0732b5f3630fd1004826c8ae5772a005",
"fix_near_grid_01.out": "722e945b2edb47697e65ec65ffeb28a7c732086016592d8fc45b7940f8df4ea1",
"max_colinear_00.in": "5d4f28d52e3dd30d222d59841d229d4b80341c93dd913302292a6621672bf2ac",
"max_colinear_00.out": "4374d79bf614f1c051cbf773224371a137db29220c3bae3e69a5c121df45d7cb",
"max_colinear_01.in": "395f91f1c4db482a7bc5b8756f10e4edbfd6d619df7cbd452a5602afbd276d02",
Expand Down
4 changes: 4 additions & 0 deletions geo/closest_pair/info.toml
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,10 @@ forum = "https://github.com/yosupo06/library-checker-problems/issues/836"
name = "near_grid.cpp"
number = 2

[[tests]]
name = "fix_near_grid.cpp"
number = 2

[[solutions]]
name = "naive.cpp"
wrong = false
Expand Down
58 changes: 58 additions & 0 deletions geo/furthest_pair/gen/fix_near_grid.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
#include <cstdio>
#include <cstdlib>
#include <utility>
#include "random.h"
#include "../params.h"

using namespace std;

using P = pair<int, int>;

P random_point(Random& gen, int LIM) {
int x = gen.uniform(-LIM, LIM);
int y = gen.uniform(-LIM, LIM);
return {x, y};
}

void out(vector<vector<P>> ALL) {
int T = ALL.size();
printf("%d\n", T);
for (auto& S: ALL) {
int n = S.size();
printf("%d\n", n);
for (auto& [x, y]: S) { printf("%d %d\n", x, y); }
}
}

int main(int, char* argv[]) {
long long seed = atoll(argv[1]);
auto gen = Random(seed);

vector<vector<P>> ALL;
int n = 1;
while ((n + 1) * (n + 1) <= SUM_N_MAX) ++n;

int eps = 100;
/*
x[0],x[1],...,x[N-1]
*/
int LIM = X_AND_Y_ABS_MAX;
int d = LIM / (n - 1);

auto get = [&](int i) -> int {
int x = i * d - (LIM / 2);
return x + gen.uniform<int>(-eps, eps);
};

vector<P> S;
for (int i = 0; i < n; ++i) {
for (int j = 0; j < n; ++j) {
int x = get(i), y = get(j);
S.emplace_back(x, y);
}
}
ALL.emplace_back(S);

out(ALL);
return 0;
}
7 changes: 6 additions & 1 deletion geo/furthest_pair/gen/near_grid.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,11 @@ void out(vector<vector<P>> ALL) {
}
}

/*
This code is not implemented as intended.
The correct implementation can be found in fix_near_grid.cpp.
https://github.com/yosupo06/library-checker-problems/issues/1204
*/
int main(int, char* argv[]) {
long long seed = atoll(argv[1]);
auto gen = Random(seed);
Expand All @@ -38,7 +43,7 @@ int main(int, char* argv[]) {
x[0],x[1],...,x[N-1]
*/
int LIM = X_AND_Y_ABS_MAX;
int d = LIM / (N - 1);
int d = LIM / (N - 1); // this line should be int d = LIM / (n - 1);

auto get = [&](int i) -> int {
int x = i * d - (LIM / 2);
Expand Down
4 changes: 4 additions & 0 deletions geo/furthest_pair/hash.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,10 @@
"all_same_00.out": "b169bd5467675d44e355b3c9e24761ca1fb76d3344e7f460ec7538938018af8f",
"example_00.in": "dc699db01795b4f323d4ea4ae7ccbe8b060f847a340003dbfd8395ac526916c0",
"example_00.out": "06df41d288d2f5041320f0edd678e8c0deb661a268a3ab892ee9cbaaaa97a7e1",
"fix_near_grid_00.in": "624a5b8059e7b97950b042bf1776580d54edd842b193c0c27525ac443168a52c",
"fix_near_grid_00.out": "a7c680fe7ab4d70a7b014987cfed4f7977bca9f33de9d0e86e33a13b1833fd1f",
"fix_near_grid_01.in": "01292b7ca2ca6cc7f4c371d8bc0160bc0732b5f3630fd1004826c8ae5772a005",
"fix_near_grid_01.out": "0148cfb2a6a4d764c0f0bbeadda3966b10895c952e8eb24557a2bf048ff67060",
"hack_uso_caliper_00.in": "68252088829480e0c707bfb4873649f0cbd17af18aa424b0c4f39b090e94b57f",
"hack_uso_caliper_00.out": "a5afc657ed265125e27a076f13d1805947eb4b52c7d2ea3e6dda0d288ba2ec87",
"hack_uso_caliper_large_00.in": "129a9441fd0cb08c4db6a331ec52b3723903be22ffa888c44d13f4cc71b5d8c5",
Expand Down
4 changes: 4 additions & 0 deletions geo/furthest_pair/info.toml
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,10 @@ forum = "https://github.com/yosupo06/library-checker-problems/issues/837"
name = "near_grid.cpp"
number = 2

[[tests]]
name = "fix_near_grid.cpp"
number = 2

[[tests]]
name = "max_convex_hull.cpp"
number = 1
Expand Down

0 comments on commit f4185dd

Please sign in to comment.