QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#167798#6412. Classical Geometry ProblemrealIyxiang#AC ✓30ms4088kbC++143.1kb2023-09-07 17:32:402023-09-07 17:32:41

Judging History

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

  • [2023-09-07 17:32:41]
  • 评测
  • 测评结果:AC
  • 用时:30ms
  • 内存:4088kb
  • [2023-09-07 17:32:40]
  • 提交

answer

#include <bits/stdc++.h>

#define eb emplace_back
#define ep emplace
#define fi first
#define se second
#define in read<int>()
#define lin read<ll>()
#define rep(i, x, y) for(int i = (x); i <= (y); i++)
#define per(i, x, y) for(int i = (x); i >= (y); i--)

using namespace std;

using ll = long long;
using db = double;
using pii = pair < int, int >;
using vec = vector < int >;
using veg = vector < pii >;

template < typename T > T read() {
	T x = 0; bool f = 0; char ch = getchar();
	while(!isdigit(ch)) f |= ch == '-', ch = getchar();
	while(isdigit(ch)) x = x * 10 + (ch ^ 48), ch = getchar();
	return f ? -x : x;
}

template < typename T > void chkmax(T &x, const T &y) { x = x > y ? x : y; }
template < typename T > void chkmin(T &x, const T &y) { x = x < y ? x : y; }

const int N = 1e6 + 10;
const db eps = 1e-10;
const db tps = 1e-16;

bool cqu(db x, db y) { return fabs(x - y) < eps; }

struct ve {
	db x, y, z;
	ve(db _x, db _y, db _z) : x(_x), y(_y), z(_z) { }
	db len() { return sqrt(x * x + y * y + z * z); }
	friend ve operator - (ve a, ve b) { return ve(a.x - b.x, a.y - b.y, a.z - b.z); }
	friend ve operator + (ve a, ve b) { return ve(a.x + b.x, a.y + b.y, a.z + b.z); }
	friend ve operator * (ve a, db b) { return ve(a.x * b, a.y * b, a.z * b); }
	friend bool operator == (ve a, ve b) {
		return cqu(a.x, b.x) & cqu(a.y, b.y) & cqu(a.z, b.z);
	}
	void set1() { db t = len(); t = 1 / t; x *= t, y *= t, z *= t; }
};

void solve() {
	ve t(0, 0, 0); t.x = in, t.y = in, t.z = in;
	vector < pair < db, ve > > ans;
	auto output = [&]() {
		printf("%d\n", ans.size());
		ve cur(0, 0, 0);
		for(auto v : ans) {
			//if(v.fi < 0) continue;
			ve t = (v.se - cur); db le = min(t.len(), v.fi); t.set1();
			cur = cur + t * le;
		}
		//cerr << "!" << cur.x << " " << cur.y << " " << cur.z << endl;
		//for(auto v : ans) assert(v.fi >= 0 && v.fi <= 10000);
		for(auto v : ans) printf("%.0lf %.0lf %.0lf %.11lf\n", v.se.x, v.se.y, v.se.z, v.fi);
	};
	ve g1(255 + tps, 255 + tps, 255 + tps);
	if(g1 == t) return ans.eb(g1.len(), g1), output();
	auto dt = [&](db x) { return cqu(x, 0) || x < 0 ? 1e4 : x; };
	ve p = g1 - t; p.set1();
	db ret = min({ dt(t.x / p.x), dt(t.y / p.y), dt(t.z / p.z) });
	if(cqu(ret, 1e4) || cqu(t.x, 0) || cqu(t.y, 0) || cqu(t.z, 0)) { }
	else {
		ans.eb(ret, g1); // reverse pos
		t = t - p * ret;
		//cerr << "!G" << t.x << " " << t.y << " " << t.z << endl;
	}
	ve g2 = g1;
	if(cqu(t.x, 0)) g2.x = tps; if(cqu(t.y, 0)) g2.y = tps; if(cqu(t.z, 0)) g2.z = tps;
	//if(t == ve(0, 0, 0)) return output();
	p = g2 - t; p.set1();
	ret = min({ dt(t.x / p.x), dt(t.y / p.y), dt(t.z / p.z) });
	if(cqu(ret, 1e4)) { }
	else {
		ans.eb(ret, g2);
		t = t - p * ret;
		//cerr << "!G" << t.x << " " << t.y << " " << t.z << endl;
	}
	ve g3 = g2;
	if(cqu(t.x, 0)) g3.x = tps; if(cqu(t.y, 0)) g3.y = tps; if(cqu(t.z, 0)) g3.z = tps;
	ans.eb(t.len(), g3);
	g3.set1();
	t = t - g3 * ans.back().fi;
	reverse(ans.begin(), ans.end()); output();
}

int main() {
#ifdef YJR_2333_TEST
	freopen("1.in", "r", stdin);
#endif
	for(int T = in; T; T--) solve(); return 0;
}

詳細信息

Test #1:

score: 100
Accepted
time: 2ms
memory: 3732kb

input:

3
105 255 175
174 174 174
0 0 0

output:

3
0 255 0 255.00000000000
0 255 255 119.00000000000
255 255 255 119.00000000000
2
0 0 0 0.00000000000
255 255 255 301.37684051698
1
0 0 0 0.00000000000

result:

ok ok (3 test cases)

Test #2:

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

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:

3
255 0 0 244.96062992126
255 255 0 121.27156248171
255 255 255 14.68387252353
3
0 255 0 244.92094861660
0 255 255 1.00472091733
255 255 255 1.41198140476
3
0 255 0 98.07692307692
0 255 255 89.64546449173
255 255 255 113.94958288739
3
0 0 255 50.32894736842
255 0 255 193.37465331366
255 255 255 77.8...

result:

ok ok (10000 test cases)

Test #3:

score: 0
Accepted
time: 19ms
memory: 3860kb

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:

3
0 255 0 128.27272727273
255 255 0 5.08489163857
255 255 255 129.12516298862
3
0 255 0 249.79591836735
0 255 255 23.61602753201
255 255 255 52.66778011012
3
0 0 255 128.70283018868
0 255 255 5.26968108967
255 255 255 57.84121950982
3
0 0 255 41.07382550336
255 0 255 113.40479220664
255 255 255 38.2...

result:

ok ok (10000 test cases)

Test #4:

score: 0
Accepted
time: 27ms
memory: 3684kb

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:

3
0 255 0 114.56521739130
255 255 0 77.42373845658
255 255 255 210.05662244037
2
0 0 255 56.98324022346
255 0 255 96.22358304762
3
255 0 0 230.58510638298
255 0 255 5.33679441042
255 255 255 223.02868413124
3
0 255 0 241.57894736842
0 255 255 37.78765499730
255 255 255 42.06442862518
3
255 0 0 162.4...

result:

ok ok (10000 test cases)

Test #5:

score: 0
Accepted
time: 27ms
memory: 3864kb

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:

3
0 0 255 231.61572052402
255 0 255 20.56786829069
255 255 255 8.16732405225
3
0 0 255 104.89361702128
255 0 255 128.34225384661
255 255 255 7.17938857175
3
255 0 0 77.74390243902
255 0 255 202.65062870412
255 255 255 20.63107222602
3
255 0 0 50.00000000000
255 255 0 261.49034442862
255 255 255 1.03...

result:

ok ok (10000 test cases)

Test #6:

score: 0
Accepted
time: 27ms
memory: 3988kb

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:

3
255 0 0 87.93103448276
255 0 255 2.97420261393
255 255 255 77.48385489368
3
0 0 255 190.63106796117
255 0 255 151.52193210226
255 255 255 13.09657188321
3
0 0 255 84.19811320755
255 0 255 35.80702888036
255 255 255 197.04207196688
3
0 0 255 81.26373626374
0 255 255 64.39513575668
255 255 255 193.8...

result:

ok ok (10000 test cases)

Test #7:

score: 0
Accepted
time: 23ms
memory: 4024kb

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:

3
255 0 0 181.86046511628
255 0 255 52.72680171427
255 255 255 122.37353965080
3
255 0 0 180.20000000000
255 0 255 14.51544567918
255 255 255 23.86451981755
3
0 255 0 237.71186440678
0 255 255 158.29803352192
255 255 255 107.03068306605
3
0 0 255 9.65909090909
0 255 255 105.40521668708
255 255 255 9...

result:

ok ok (10000 test cases)

Test #8:

score: 0
Accepted
time: 19ms
memory: 3740kb

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:

3
0 0 255 131.89655172414
0 255 255 116.42610096107
255 255 255 69.29797904532
3
255 0 0 212.50000000000
255 0 255 71.31514690694
255 255 255 28.53244080620
3
0 0 255 170.00000000000
0 255 255 78.12227815638
255 255 255 64.92926579105
3
255 0 0 246.10465116279
255 255 0 25.38192136637
255 255 255 86...

result:

ok ok (10000 test cases)

Test #9:

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

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:

3
0 255 0 73.21782178218
255 255 0 180.26489795131
255 255 255 19.17015644065
3
0 0 255 130.30837004405
0 255 255 22.98411661321
255 255 255 11.44466170744
3
0 255 0 62.02702702703
0 255 255 272.83393729684
255 255 255 3.05043118026
2
255 0 0 158.77358490566
255 255 0 45.95972744495
3
255 0 0 71.718...

result:

ok ok (10000 test cases)

Test #10:

score: 0
Accepted
time: 27ms
memory: 4020kb

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:

3
255 0 0 209.46428571429
255 255 0 214.80850384034
255 255 255 92.35844696646
3
0 0 255 189.11483253589
255 0 255 14.30084979385
255 255 255 47.52775582714
3
0 0 255 113.33333333333
255 0 255 213.57304191274
255 255 255 90.99267252961
3
0 0 255 148.33333333333
255 0 255 109.25317154138
255 255 255 ...

result:

ok ok (10000 test cases)

Test #11:

score: 0
Accepted
time: 20ms
memory: 4088kb

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:

3
255 0 0 148.93805309735
255 0 255 16.11036737558
255 255 255 192.82513127183
3
0 0 0 0.00000000000
255 0 255 330.57242020471
255 255 255 172.18340512372
3
255 0 0 130.18421052632
255 255 0 42.01335111866
255 255 255 44.10729871114
3
0 255 0 131.48437500000
0 255 255 62.19641260808
255 255 255 11.9...

result:

ok ok (10000 test cases)

Test #12:

score: 0
Accepted
time: 22ms
memory: 3856kb

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:

3
0 255 0 26.25000000000
255 255 0 85.16837815565
255 255 255 105.14497528780
3
0 0 255 18.82550335570
0 255 255 94.94535702993
255 255 255 70.38180907156
3
0 255 0 172.63975155280
0 255 255 47.85188221496
255 255 255 77.94103742890
3
0 255 0 121.22950819672
0 255 255 191.97169291017
255 255 255 76....

result:

ok ok (10000 test cases)

Test #13:

score: 0
Accepted
time: 24ms
memory: 3680kb

input:

10000
170 100 234
20 253 12
243 196 46
206 129 235
149 5 166
232 179 7
149 75 45
98 197 156
206 22 133
230 176 54
159 228 135
170 92 118
90 61 180
9 26 18
21 65 122
40 143 87
125 192 199
176 35 144
44 85 243
153 238 203
227 9 212
200 74 226
253 135 20
139 117 222
230 43 212
42 201 224
22 222 152
191...

output:

3
0 0 255 192.00000000000
255 0 255 118.62384695143
255 255 255 114.85139473253
3
0 255 0 252.82978723404
255 255 0 8.39536575410
255 255 255 16.69384158600
3
255 0 0 203.13559322034
255 255 0 186.76141133680
255 255 255 47.87068690518
3
0 0 255 150.91836734694
255 0 255 168.31423009447
255 255 255 ...

result:

ok ok (10000 test cases)

Test #14:

score: 0
Accepted
time: 27ms
memory: 3732kb

input:

10000
67 216 241
14 40 250
28 215 219
200 241 181
3 167 13
227 218 113
85 72 151
116 20 162
202 252 17
54 184 231
49 90 219
117 173 19
37 53 223
10 195 119
118 128 187
46 208 215
54 85 104
71 99 34
234 95 0
44 223 10
14 248 47
123 70 75
245 118 231
131 187 137
34 62 21
4 118 233
40 183 96
242 97 190...

output:

3
0 0 255 163.46153846154
0 255 255 214.72822797246
255 255 255 68.60812019622
3
0 0 255 249.06976744186
0 255 255 27.51781169569
255 255 255 18.76366532550
3
0 0 255 25.50000000000
0 255 255 282.61500558798
255 255 255 28.77606415190
3
0 255 0 190.09090909091
255 255 0 67.56079238982
255 255 255 22...

result:

ok ok (10000 test cases)

Test #15:

score: 0
Accepted
time: 26ms
memory: 3860kb

input:

10000
252 245 224
4 171 9
240 190 208
69 15 254
4 230 90
0 255 17
6 26 58
150 187 237
239 242 146
255 227 231
232 117 26
44 255 111
183 1 9
121 85 207
15 245 120
247 181 40
1 255 164
244 139 255
131 248 27
161 24 241
63 44 16
207 36 251
15 227 163
49 7 180
27 7 23
61 254 235
14 8 11
200 7 3
26 254 3...

output:

3
255 0 0 178.50000000000
255 255 0 180.34787533941
255 255 255 236.36230324970
3
0 255 0 167.92682926829
0 255 255 5.36765683677
255 255 255 5.75854760008
3
255 0 0 173.61702127660
255 0 255 74.12449676002
255 255 255 238.53095763753
3
0 0 255 253.62903225806
255 0 255 57.37582920837
255 255 255 18...

result:

ok ok (10000 test cases)

Test #16:

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

input:

10000
10 7 240
232 252 180
5 169 10
1 40 6
252 2 242
245 8 5
249 17 249
255 2 233
12 3 1
2 6 253
252 254 2
251 245 6
254 4 252
10 244 245
254 218 52
255 8 4
20 112 248
253 0 254
250 234 1
226 245 216
11 6 2
245 139 0
8 28 233
1 11 24
246 250 253
9 124 17
255 26 1
14 251 46
2 14 248
233 1 44
12 255 1...

output:

3
0 0 255 239.38775510204
255 0 255 3.09045337298
255 255 255 9.84890567668
3
0 255 0 221.73913043478
255 255 0 178.29762675118
255 255 255 188.41146461933
3
0 255 0 165.48979591837
0 255 255 5.40507452806
255 255 255 7.20891115218
3
0 255 0 34.81927710843
0 255 255 6.63197567662
255 255 255 1.63630...

result:

ok ok (10000 test cases)

Test #17:

score: 0
Accepted
time: 17ms
memory: 4088kb

input:

10000
0 3 254
9 1 2
250 254 0
4 1 65
212 3 253
253 255 254
252 1 255
255 230 11
253 215 255
113 12 16
252 253 0
255 254 254
254 255 252
0 32 254
255 36 252
10 1 243
3 46 11
99 3 255
250 0 248
11 5 3
253 254 255
23 2 1
0 253 4
255 255 248
255 237 250
7 13 1
251 251 246
0 0 4
0 2 1
254 254 0
189 3 0
2...

output:

2
0 0 255 253.98809523810
0 255 255 3.00002362047
3
255 0 0 7.05533596838
255 0 255 1.40027784603
255 255 255 1.71176556814
2
0 255 0 204.00000000000
255 255 0 254.95097567964
3
0 0 255 61.97211155378
255 0 255 3.77740034351
255 255 255 1.59250386880
3
0 0 255 243.13953488372
255 0 255 211.716731083...

result:

ok ok (10000 test cases)

Test #18:

score: 0
Accepted
time: 15ms
memory: 3740kb

input:

10000
0 253 255
255 252 2
255 0 255
250 253 255
253 0 255
252 251 236
8 255 0
247 254 254
2 255 255
255 255 252
0 0 4
6 250 0
7 32 0
0 2 255
255 9 255
3 255 1
255 255 242
254 0 0
0 0 254
0 255 255
1 0 9
255 255 2
0 255 0
0 0 255
254 9 1
253 255 254
252 0 255
0 0 255
254 0 252
255 247 0
2 250 255
255...

output:

2
0 0 255 255.00000000000
0 255 255 253.00000000000
3
255 0 0 255.00000000000
255 255 0 251.97628458498
255 255 255 2.00014060029
1
255 0 255 360.62445840514
3
0 0 255 255.00000000000
0 255 255 153.00000000000
255 255 255 269.25824035673
2
0 0 255 255.00000000000
255 0 255 253.00000000000
3
255 0 0 ...

result:

ok ok (10000 test cases)

Test #19:

score: 0
Accepted
time: 14ms
memory: 3680kb

input:

10000
0 0 0
255 0 255
0 255 255
255 255 1
0 0 0
0 255 1
255 0 254
0 255 0
0 203 255
0 2 0
255 0 255
255 254 0
255 0 255
255 255 228
0 255 255
0 255 255
0 254 0
253 0 0
242 0 0
255 0 0
255 252 0
0 0 0
0 0 0
255 255 255
0 0 255
255 255 0
4 255 0
0 1 0
0 0 255
0 253 253
0 255 255
0 0 255
255 0 0
1 255 ...

output:

1
0 0 0 0.00000000000
1
255 0 255 360.62445840514
1
0 255 255 360.62445840514
2
255 255 0 360.62445840514
255 255 255 1.00000000000
1
0 0 0 0.00000000000
2
0 255 0 255.00000000000
0 255 255 1.00000000000
2
255 0 0 255.00000000000
255 0 255 254.00000000000
1
0 255 0 255.00000000000
2
0 0 255 255.0000...

result:

ok ok (10000 test cases)

Test #20:

score: 0
Accepted
time: 7ms
memory: 3744kb

input:

10000
0 0 0
0 255 255
255 0 255
255 255 0
255 255 255
255 0 0
255 255 255
0 0 255
0 0 0
0 0 255
255 255 0
0 0 255
255 0 0
0 0 0
255 255 0
0 0 255
0 0 0
255 255 0
0 0 255
0 255 0
255 0 255
0 255 255
0 255 0
0 255 0
1 0 255
255 0 254
255 0 255
255 255 255
0 255 255
255 0 255
255 0 255
0 255 255
255 25...

output:

1
0 0 0 0.00000000000
1
0 255 255 360.62445840514
1
255 0 255 360.62445840514
1
255 255 0 360.62445840514
1
255 255 255 441.67295593006
1
255 0 0 255.00000000000
1
255 255 255 441.67295593006
1
0 0 255 255.00000000000
1
0 0 0 0.00000000000
1
0 0 255 255.00000000000
1
255 255 0 360.62445840514
1
0 0 ...

result:

ok ok (10000 test cases)