QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#275726#6412. Classical Geometry Problemucup-team859WA 30ms4052kbC++179.1kb2023-12-04 23:48:352023-12-04 23:48:35

Judging History

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

  • [2023-12-04 23:48:35]
  • 评测
  • 测评结果:WA
  • 用时:30ms
  • 内存:4052kb
  • [2023-12-04 23:48:35]
  • 提交

answer

#include <bits/stdc++.h>

using namespace std;
const double EPS = 1e-9;

struct Point {
    double x, y, z;
}v[8];
vector <pair <int, double>> ans;

int sgn(double d) {
    return (d > EPS) - (d < -EPS);
}

bool okPoint(Point p) {
    return sgn(p.x) >= 0 && sgn(255 - p.x) >= 0 && sgn(p.y) >= 0 && sgn(255 - p.y) >= 0 && sgn(p.z) >= 0 && sgn(255 - p.z) >= 0;
}

void printPoint(Point p) {
    cout << p.x << ' ' << p.y << ' ' << p.z << '\n';
}

double pointDist(Point a, Point b) {
    double dx = (a.x - b.x) * (a.x - b.x);
    double dy = (a.y - b.y) * (a.y - b.y);
    double dz = (a.z - b.z) * (a.z - b.z);
    return sqrt(dx + dy + dz);
}

Point moveToFace(Point p) {
    for (int i = 7; i >= 0; i--) {
        Point np;
        np.x = 255 - v[i].x;
        np.y = v[i].y - (v[i].x - np.x) / (p.x - v[i].x) * (p.y - v[i].y);
        np.z = v[i].z - (v[i].x - np.x) / (p.x - v[i].x) * (p.z - v[i].z);
        if (okPoint(np)) {
            double dist = pointDist(v[i], np) * (p.x - np.x) / (v[i].x - np.x);
            ans.push_back({i, dist});
            return np;
        }
        np.y = 255 - v[i].y;
        np.x = v[i].x - (v[i].y - np.y) / (p.y - v[i].y) * (p.x - v[i].x);
        np.z = v[i].z - (v[i].y - np.y) / (p.y - v[i].y) * (p.z - v[i].z);
        if (okPoint(np)) {
            double dist = pointDist(v[i], np) * (p.x - np.x) / (v[i].x - np.x);
            ans.push_back({i, dist});
            return np;
        }
        np.z = 255 - v[i].z;
        np.x = v[i].x - (v[i].z - np.z) / (p.z - v[i].z) * (p.x - v[i].x);
        np.y = v[i].y - (v[i].z - np.z) / (p.z - v[i].z) * (p.y - v[i].y);
        if (okPoint(np)) {
            double dist = pointDist(v[i], np) * (p.x - np.x) / (v[i].x - np.x);
            ans.push_back({i, dist});
            return np;
        }
    }
    cout << "EROARE MARE\n";
    return {0, 0, 0};
}

void solveFace(Point p, vector <int> face) {
    for (int i = 0; i < 4; i++) {
        Point c = v[face[i]];
        if (sgn(c.x - p.x) == 0 && sgn(c.y - p.y) == 0 && sgn(c.z - p.z) == 0) {
            double dist = pointDist(c, v[0]);
            ans.push_back({face[i], dist});
            return;
        }
    }
    for (int i = 0; i < 4; i++) {
        Point c = v[face[i]];
        Point c2 = c;
        double dist;
        if (sgn(c.x - p.x) == 0 && sgn(c.y - p.y) == 0) {
            c2.z = 255 - c.z;
            dist = pointDist(c, c2) * (p.z - c.z) / (c2.z - c.z);
            int aux = face[i];
            if (c.z == 0) aux += 4;
            if (c.z == 255) aux -= 4;
            ans.push_back({aux, dist});
            dist = pointDist(c, v[0]);
            ans.push_back({face[i], dist});
            return;
        }
        if (sgn(c.x - p.x) == 0 && sgn(c.z - p.z) == 0) {
            c2.y = 255 - c.y;
            dist = pointDist(c, c2) * (p.y - c.y) / (c2.y - c.y);
            int aux = face[i];
            if (c.y == 0) aux += 2;
            if (c.y == 255) aux -= 2;
            ans.push_back({aux, dist});
            dist = pointDist(c, v[0]);
            ans.push_back({face[i], dist});
            return;
        }
        if (sgn(c.y - p.y) == 0 && sgn(c.z - p.z) == 0) {
            c2.x = 255 - c.x;
            dist = pointDist(c, c2) * (p.x - c.x) / (c2.x - c.x);
            int aux = face[i];
            if (c.x == 0) aux++;
            if (c.x == 255) aux--;
            ans.push_back({aux, dist});
            dist = pointDist(c, v[0]);
            ans.push_back({face[i], dist});
            return;
        }
    }
    Point np;
    for (int i = 0; i < 4; i++) {
        Point c = v[face[i]];
        if (sgn(c.x - p.x) == 0) {
            np = p;
            np.y = 255 - c.y;
            np.z = c.z - (c.y - np.y) / (p.y - c.y) * (p.z - c.z);
            if (sgn(np.z) >= 0 && sgn(255 - np.z) >= 0) {
                double dist = pointDist(c, np) * (p.y - np.y) / (c.y - np.y);
                ans.push_back({face[i], dist});
                break;
            }
            np = p;
            np.z = 255 - c.z;
            np.y = c.y - (c.z - np.z) / (p.z - c.z) * (p.y - c.y);
            if (sgn(np.y) >= 0 && sgn(255 - np.y) >= 0) {
                double dist = pointDist(c, np) * (p.z - np.z) / (c.z - np.z);
                ans.push_back({face[i], dist});
                break;
            }
        }
        if (sgn(c.y - p.y) == 0) {
            np = p;
            np.x = 255 - c.x;
            np.z = c.z - (c.x - np.x) / (p.x - c.x) * (p.z - c.z);
            if (sgn(np.z) >= 0 && sgn(255 - np.z) >= 0) {
                double dist = pointDist(c, np) * (p.x - np.x) / (c.x - np.x);
                ans.push_back({face[i], dist});
                break;
            }
            np = p;
            np.z = 255 - c.z;
            np.x = c.x - (c.z - np.z) / (p.z - c.z) * (p.x - c.x);
            if (sgn(np.x) >= 0 && sgn(255 - np.x) >= 0) {
                double dist = pointDist(c, np) * (p.z - np.z) / (c.z - np.z);
                ans.push_back({face[i], dist});
                break;
            }
        }
        if (sgn(c.z - p.z) == 0) {
            np = p;
            np.y = 255 - c.y;
            np.x = c.x - (c.y - np.y) / (p.y - c.y) * (p.x - c.x);
            if (sgn(np.x) >= 0 && sgn(255 - np.x) >= 0) {
                double dist = pointDist(c, np) * (p.y - np.y) / (c.y - np.y);
                ans.push_back({face[i], dist});
                break;
            }
            np = p;
            np.x = 255 - c.x;
            np.y = c.y - (c.x - np.x) / (p.x - c.x) * (p.y - c.y);
            if (sgn(np.y) >= 0 && sgn(255 - np.y) >= 0) {
                double dist = pointDist(c, np) * (p.x - np.x) / (c.x - np.x);
                ans.push_back({face[i], dist});
                break;
            }
        }
    }
    p = np;
    for (int i = 0; i < 4; i++) {
        Point c = v[face[i]];
        if (sgn(c.x - p.x) == 0 && sgn(c.y - p.y) == 0 && sgn(c.z - p.z) == 0) {
            double dist = pointDist(c, v[0]);
            ans.push_back({face[i], dist});
            return;
        }
    }
    for (int i = 0; i < 4; i++) {
        Point c = v[face[i]];
        Point c2 = c;
        double dist;
        if (sgn(c.x - p.x) == 0 && sgn(c.y - p.y) == 0) {
            c2.z = 255 - c.z;
            dist = pointDist(c, c2) * (p.z - c.z) / (c2.z - c.z);
            int aux = face[i];
            if (c.z == 0) aux += 4;
            if (c.z == 255) aux -= 4;
            ans.push_back({aux, dist});
            dist = pointDist(c, v[0]);
            ans.push_back({face[i], dist});
            return;
        }
        if (sgn(c.x - p.x) == 0 && sgn(c.z - p.z) == 0) {
            c2.y = 255 - c.y;
            dist = pointDist(c, c2) * (p.y - c.y) / (c2.y - c.y);
            int aux = face[i];
            if (c.y == 0) aux += 2;
            if (c.y == 255) aux -= 2;
            ans.push_back({aux, dist});
            dist = pointDist(c, v[0]);
            ans.push_back({face[i], dist});
            return;
        }
        if (sgn(c.y - p.y) == 0 && sgn(c.z - p.z) == 0) {
            c2.x = 255 - c.x;
            dist = pointDist(c, c2) * (p.x - c.x) / (c2.x - c.x);
            int aux = face[i];
            if (c.x == 0) aux++;
            if (c.x == 255) aux--;
            ans.push_back({aux, dist});
            dist = pointDist(c, v[0]);
            ans.push_back({face[i], dist});
            return;
        }
    }
}

void solve() {
    Point p;
    cin >> p.x >> p.y >> p.z;
    bool onFace = 0;
    if (sgn(p.x) == 0 || sgn(p.x - 255) == 0 || sgn(p.y) == 0 || sgn(p.y - 255) == 0 || sgn(p.z) == 0 || sgn(p.z - 255) == 0) {
        onFace = 1;
    }
    if (!onFace) {
        p = moveToFace(p);
    }
    vector <int> face;
    for (int i = 0; i < 8; i++) {
        if (sgn(p.x - v[i].x) == 0 || sgn(p.y - v[i].y) == 0 || sgn(p.z - v[i].z) == 0) {
            face.push_back(i);
        }
    }
    solveFace(p, face);
    reverse(ans.begin(), ans.end());
    cout << ans.size() << '\n';
    p = {0, 0, 0};
    for (auto pr : ans) {
        cout << (int) v[pr.first].x << ' ' << (int) v[pr.first].y << ' ' << (int) v[pr.first].z << ' ' << pr.second << '\n';
        Point np = p;
        if (pointDist(p, v[pr.first]) == 0) {
            continue;
        }
        np.x = p.x + (v[pr.first].x - p.x) * pr.second / pointDist(p, v[pr.first]);
        np.y = p.y + (v[pr.first].y - p.y) * pr.second / pointDist(p, v[pr.first]);
        np.z = p.z + (v[pr.first].z - p.z) * pr.second / pointDist(p, v[pr.first]);
        //printPoint(np);
        p = np;
    }
    ans.clear();
}

int main() {
#ifdef LOCAL
    freopen("test.in", "r", stdin);
    freopen("test.out", "w", stdout);
#endif // LOCAL
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    for (int i = 0; i < 8; i++) {
        v[i].x = ((i & 1) != 0) * 255;
        v[i].y = ((i & 2) != 0) * 255;
        v[i].z = ((i & 4) != 0) * 255;
    }
    int nrTeste;
    cin >> nrTeste;
    cout << fixed << setprecision(10);
    while (nrTeste--) {
        solve();
    }
    return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 0ms
memory: 3824kb

input:

3
105 255 175
174 174 174
0 0 0

output:

3
0 255 255 360.6244584051
255 255 255 153.0000000000
0 255 0 93.2952303175
2
0 0 0 0.0000000000
255 255 255 301.3768405170
1
0 0 0 0.0000000000

result:

ok ok (3 test cases)

Test #2:

score: 0
Accepted
time: 29ms
memory: 3840kb

input:

10000
250 128 13
1 245 2
88 183 138
179 69 194
153 246 33
255 119 192
233 30 108
26 208 33
53 162 189
225 130 10
202 137 121
152 198 25
49 165 180
228 56 30
74 18 14
6 115 31
168 242 206
90 238 139
44 103 60
16 21 190
229 209 68
41 171 181
39 74 73
181 96 18
234 95 70
75 174 84
101 16 44
202 249 80
...

output:

4
255 0 0 255.0000000000
255 255 0 123.7341772152
0 0 0 5.8560858341
255 255 255 14.6838725235
4
0 255 0 255.0000000000
0 255 255 1.0450819672
0 0 0 10.0394543918
255 255 255 1.4119814048
4
0 255 0 255.0000000000
0 255 255 134.2105263158
0 0 0 124.2376040857
255 255 255 113.9495828874
4
0 0 255 255....

result:

ok ok (10000 test cases)

Test #3:

score: 0
Accepted
time: 29ms
memory: 4052kb

input:

10000
90 173 87
39 251 59
39 43 150
106 29 130
52 55 180
236 225 70
171 15 48
92 133 240
182 226 10
126 139 105
196 7 204
32 131 193
27 96 218
67 29 33
159 9 251
130 111 243
226 69 39
198 131 80
108 169 147
45 36 170
76 138 251
55 235 186
224 165 48
51 133 173
225 14 226
234 70 139
178 92 174
138 24...

output:

4
0 255 0 255.0000000000
255 255 0 8.8953488372
0 0 0 124.5399913660
255 255 255 129.1251629886
4
0 255 0 255.0000000000
0 255 255 24.0566037736
0 0 0 4.7431894784
255 255 255 52.6677801101
4
0 0 255 255.0000000000
0 255 255 9.1891891892
0 0 0 124.0387931119
255 255 255 57.8412195098
4
0 0 255 255.0...

result:

ok ok (10000 test cases)

Test #4:

score: 0
Accepted
time: 29ms
memory: 3848kb

input:

10000
186 217 161
76 0 116
246 159 161
32 245 65
206 120 71
217 76 204
109 255 245
157 59 192
55 35 87
27 147 199
190 134 31
169 64 105
5 27 255
161 2 35
244 255 232
253 106 199
28 151 129
50 24 20
172 236 234
74 51 150
179 68 178
69 42 192
152 1 23
177 169 71
216 190 125
136 223 193
255 168 49
74 2...

output:

4
0 255 0 255.0000000000
255 255 0 113.8392857143
0 0 0 112.8910631851
255 255 255 210.0566224404
3
0 0 255 255.0000000000
255 0 255 167.0689655172
0 0 0 166.1762813412
4
255 0 0 255.0000000000
255 0 255 5.8620689655
0 0 0 23.9125660503
255 255 255 223.0286841312
4
0 255 0 255.0000000000
0 255 255 3...

result:

ok ok (10000 test cases)

Test #5:

score: 0
Accepted
time: 29ms
memory: 3964kb

input:

10000
26 6 234
114 6 172
198 19 173
214 204 1
104 186 218
199 182 82
47 240 186
223 240 143
184 99 164
184 155 37
185 4 114
49 253 17
239 214 37
0 231 38
73 245 212
121 102 155
86 234 219
157 173 216
236 46 65
103 67 130
27 253 105
83 105 197
81 93 254
47 206 225
207 110 24
38 119 248
76 243 180
10 ...

output:

4
0 0 255 255.0000000000
255 0 255 22.3684210526
0 0 0 21.5886064757
255 255 255 8.1673240523
4
0 0 255 255.0000000000
255 0 255 165.9036144578
0 0 0 101.4062288741
255 255 255 7.1793885718
4
255 0 0 255.0000000000
255 0 255 219.3854748603
0 0 0 81.2455721505
255 255 255 20.6310722260
4
255 0 0 255....

result:

ok ok (10000 test cases)

Test #6:

score: 0
Accepted
time: 29ms
memory: 3964kb

input:

10000
122 50 52
152 12 229
149 135 184
140 164 193
2 251 109
180 33 217
241 225 126
33 165 94
57 163 242
85 164 132
179 131 197
185 186 185
216 145 74
95 203 40
158 236 193
245 97 111
144 61 52
9 67 157
44 113 152
132 82 110
130 182 33
96 168 202
10 184 228
173 243 124
198 29 180
196 15 47
153 63 54...

output:

4
255 0 0 255.0000000000
255 0 255 7.0833333333
0 0 0 165.5028388668
255 255 255 77.4838548937
4
0 0 255 255.0000000000
255 0 255 164.5161290323
0 0 0 32.4694269279
255 255 255 13.0965718832
4
0 0 255 255.0000000000
255 0 255 72.8571428571
0 0 0 156.9123685065
255 255 255 197.0420719669
4
0 0 255 25...

result:

ok ok (10000 test cases)

Test #7:

score: 0
Accepted
time: 30ms
memory: 3780kb

input:

10000
218 94 126
189 17 30
100 251 196
67 123 128
157 60 0
161 139 95
179 210 67
98 91 45
186 227 63
242 172 226
173 1 24
66 118 98
194 75 112
189 176 43
243 226 174
112 93 67
202 143 142
117 216 97
108 179 239
161 97 91
233 111 216
110 231 208
195 20 203
43 24 22
189 205 79
98 167 102
230 139 185
1...

output:

4
255 0 0 255.0000000000
255 0 255 65.8064516129
0 0 0 60.5224175317
255 255 255 122.3735396508
4
255 0 0 255.0000000000
255 0 255 19.2732558140
0 0 0 70.9159774329
255 255 255 23.8645198176
4
0 255 0 255.0000000000
0 255 255 162.1192052980
0 0 0 7.7979751037
255 255 255 107.0306830661
4
0 0 255 255...

result:

ok ok (10000 test cases)

Test #8:

score: 0
Accepted
time: 25ms
memory: 3952kb

input:

10000
58 139 199
227 23 87
52 111 207
249 83 64
55 125 147
142 246 229
118 194 7
164 16 252
59 36 140
143 180 64
167 127 108
202 51 10
172 6 150
28 149 45
72 217 154
236 88 23
4 226 232
225 109 37
172 245 69
190 112 71
81 40 143
124 38 213
124 112 178
169 61 176
180 125 234
1 63 157
51 215 59
75 216...

output:

4
0 0 255 255.0000000000
0 255 255 146.4893617021
0 0 0 83.5968703857
255 255 255 69.2979790453
4
255 0 0 255.0000000000
255 0 255 80.0000000000
0 0 0 32.2548607256
255 255 255 28.5324408062
4
0 0 255 255.0000000000
0 255 255 97.0645161290
0 0 0 64.5159952186
255 255 255 64.9292657911
4
255 0 0 255....

result:

ok ok (10000 test cases)

Test #9:

score: 0
Accepted
time: 25ms
memory: 4052kb

input:

10000
154 183 17
8 28 144
3 227 218
175 43 0
209 191 38
123 96 107
56 179 204
230 197 204
188 100 217
43 189 158
161 254 191
83 240 178
150 193 187
123 122 48
157 207 135
103 84 235
62 53 66
77 2 234
237 56 156
219 127 51
184 225 70
138 102 218
53 203 153
39 98 75
171 45 134
159 215 212
128 35 190
1...

output:

4
0 255 0 255.0000000000
255 255 0 210.4518072289
0 0 0 100.0219565836
255 255 255 19.1701564407
4
0 0 255 255.0000000000
0 255 255 37.5000000000
0 0 0 115.8276480240
255 255 255 11.4446617074
4
0 255 0 255.0000000000
0 255 255 244.7544642857
0 0 0 39.2726694443
255 255 255 3.0504311803
3
255 0 0 25...

result:

ok ok (10000 test cases)

Test #10:

score: 0
Accepted
time: 29ms
memory: 3840kb

input:

10000
250 227 91
46 34 201
210 87 230
102 2 191
107 0 185
104 203 241
250 164 144
40 123 155
61 164 38
200 197 253
155 124 18
219 173 90
127 124 225
217 94 50
242 198 116
227 79 191
120 136 155
184 151 174
45 122 243
248 142 31
31 154 253
152 165 224
238 39 128
165 134 229
162 220 33
61 111 11
205 1...

output:

4
255 0 0 255.0000000000
255 255 0 218.1132075472
0 0 0 10.2303904838
255 255 255 92.3584469665
4
0 0 255 255.0000000000
255 0 255 18.3233532934
0 0 0 62.4683426673
255 255 255 47.5277558271
4
0 0 255 255.0000000000
255 0 255 219.3356643357
0 0 0 50.0524839803
255 255 255 90.9926725296
4
0 0 255 255...

result:

ok ok (10000 test cases)

Test #11:

score: 0
Accepted
time: 25ms
memory: 3776kb

input:

10000
208 135 142
248 171 248
162 65 32
9 162 63
91 20 90
188 236 117
62 200 71
14 228 53
68 196 133
27 159 255
129 86 121
46 216 3
213 65 177
7 28 45
215 136 153
108 54 113
254 122 99
243 222 89
18 255 48
14 157 204
210 33 132
87 4 33
231 222 233
30 14 100
10 45 226
49 210 232
113 79 18
235 109 14
...

output:

4
255 0 0 255.0000000000
255 0 255 24.4520547945
0 0 0 100.3331231625
255 255 255 192.8251312718
3
255 0 255 360.6244584051
0 0 0 30.0520382004
255 255 255 172.1834051237
4
255 0 0 255.0000000000
255 255 0 64.7307692308
0 0 0 109.7181369491
255 255 255 44.1072987111
4
0 255 0 255.0000000000
0 255 25...

result:

ok ok (10000 test cases)

Test #12:

score: -100
Wrong Answer
time: 29ms
memory: 3896kb

input:

10000
119 133 74
50 106 117
59 203 94
72 223 194
202 156 197
61 81 108
77 80 107
240 230 250
53 54 66
133 197 44
33 113 2
83 54 163
206 241 33
41 83 202
182 57 124
37 155 241
186 245 218
153 80 29
47 83 212
41 32 94
107 89 186
58 161 214
114 106 34
17 89 16
19 117 170
169 115 74
55 143 33
6 182 196
...

output:

4
0 255 0 255.0000000000
255 255 0 194.4915254237
0 0 0 216.1660705842
255 255 255 105.1449752878
4
0 0 255 255.0000000000
0 255 255 213.1343283582
0 0 0 223.7229447497
255 255 255 70.3818090716
4
0 255 0 255.0000000000
0 255 255 61.9791666667
0 0 0 69.6227248766
255 255 255 77.9410374289
4
0 255 0 ...

result:

wrong answer too far from the target: (0.000000, 0.000000, 0.000000) instead of (207, 255, 255) (test case 149)