Skip to content

Commit 5905c85

Browse files
committed
Update generator of two squares
1 parent 0039ffc commit 5905c85

File tree

1 file changed

+23
-16
lines changed

1 file changed

+23
-16
lines changed

two-squares/tests/generator.cpp

+23-16
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,8 @@ vector<vector<P>> handmade_med = {
1515
{{-3000,-3000}, {3000,-3000}, {-3000,3000}, {3000,3000}, {-3000,-3000}, {2999,-3000}, {-3000,2999}, {2999,2999}},
1616
{{-3000,3000}, {0,3000}, {-3000,0}, {0,0}, {0,0}, {0,3000}, {3000,0}, {3000,3000}},
1717
{{-3000,-3000}, {-3000,-2999}, {-2999,-3000}, {-2999,-2999}, {-3000,3000}, {-3000,2999}, {-2999,3000}, {-2999,2999}},
18-
{{-3000,-3000}, {-3000, -3000}, {3000,-3000}, {3000, -3000}, {-3000,3000}, {-3000,3000}, {3000,3000}, {3000,3000}}
18+
{{-3000,-3000}, {-3000, -3000}, {3000,-3000}, {3000, -3000}, {-3000,3000}, {-3000,3000}, {3000,3000}, {3000,3000}},
19+
{{0,0}, {1,0}, {0,1}, {1,1}, {2,0}, {3,0}, {2,1}, {3,1}}
1920
};
2021

2122
vector<vector<P>> handmade_large = {
@@ -25,13 +26,19 @@ vector<vector<P>> handmade_large = {
2526
};
2627

2728

28-
void shuffle_and_output(ostream &os, vector<P> v) {
29+
void shuffle_and_output(ostream &os, vector<vector<P>> &vec) {
30+
shuffle(begin(vec), end(vec));
31+
for(auto &v : vec) {
32+
for(int i=0; i<8; i++) os << v[i].first << " " << v[i].second << (i==7 ? "\n" : " ");
33+
}
34+
}
35+
36+
void shuffle_vector(vector<P> &v) {
2937
assert(v.size() == 8);
3038
shuffle(begin(v), end(v));
31-
for(int i=0; i<8; i++) os << v[i].first << " " << v[i].second << (i==7 ? "\n" : " ");
3239
}
3340

34-
bool validate_and_answer(ostream &os, const vector<P> &v) {
41+
bool validate(const vector<P> &v) {
3542
if(v.size() != 8) return false;
3643

3744
for(int i=0; i<8; i++){
@@ -69,18 +76,12 @@ bool validate_and_answer(ostream &os, const vector<P> &v) {
6976
if(l1>0 && l2>0) ans[{min(l1,l2), max(l1,l2)}]++;
7077
}
7178

72-
if(ans.size() == 1){
73-
os << ans.begin()->first.first << " " << ans.begin()->first.second << endl;
74-
return true;
75-
} else {
76-
return false;
77-
}
79+
return ans.size() == 1;
7880
}
7981

8082

81-
void generate(const string &file_name, int num_case, int max_abs, const vector<vector<P>> &hand_cases, bool is_parallel = false) {
83+
void generate(const string &file_name, int num_case, int max_abs, vector<vector<P>> hand_cases, bool is_parallel = false) {
8284
ofstream in_ofs(file_name + ".in");
83-
ofstream diff_ofs(file_name + ".diff");
8485
in_ofs << num_case << endl;
8586

8687
auto gen_square = [max_abs, is_parallel](){
@@ -101,20 +102,26 @@ void generate(const string &file_name, int num_case, int max_abs, const vector<v
101102
return vector<P>({p1, p2, p3, p4});
102103
};
103104

105+
vector<vector<P>> cases;
106+
104107
for (int i=0; i + hand_cases.size()<num_case; i++) {
105108
vector<P> v;
106109
do {
107110
v = gen_square();
108111
auto tmp = gen_square();
109112
v.insert(v.end(), tmp.begin(), tmp.end());
110-
} while(!validate_and_answer(diff_ofs, v));
111-
shuffle_and_output(in_ofs, v);
113+
} while(!validate(v));
114+
shuffle_vector(v);
115+
cases.push_back(v);
112116
}
113117

114118
for (auto &v : hand_cases) {
115-
assert(validate_and_answer(diff_ofs, v));
116-
shuffle_and_output(in_ofs, v);
119+
assert(validate(v));
120+
shuffle_vector(v);
121+
cases.push_back(v);
117122
}
123+
124+
shuffle_and_output(in_ofs, cases);
118125
}
119126

120127

0 commit comments

Comments
 (0)