萌新刚学oi1秒,90分求调!!
查看原帖
萌新刚学oi1秒,90分求调!!
891956
TempestMiku楼主2023/7/23 10:55
#include<bits/stdc++.h>
#define int long long
using namespace std;
namespace Testify{
    inline int read(){
        int f(1),x(0);
        char ch=getchar();
        for(;!isdigit(ch);ch=getchar()) if(ch=='-') f=-1;
        for(;isdigit(ch);ch=getchar()) x=(x<<1)+(x<<3)+(ch^48);
        return f*x;
    }
    inline void Write(int x){
        if(x>9) Write(x/10);
        putchar(x%10+48);
    }
    inline void write(int x){
        if(x<0) putchar('-'),x=-x;
        Write(x);
        putchar('\n');
    }
}
using namespace Testify;
const int N=1005;
int n,m,cat,mouse;  
int head[N],nxt[N<<1],to[N<<1],tot(0);
int d[N],dis[N][N],op[N][N];
double dp[N][N];//老鼠在i点,猫在j点的期望步数
bool vis[N],visi[N][N];
inline void add(int x,int y){
    to[++tot]=y,nxt[tot]=head[x],head[x]=tot;
    return ;
}
typedef pair<int,int > P;
inline void dij(int now){
    for(register int i=1;i<=n;i++){
        dis[now][i]=INT_MAX;
        vis[i]=0;
    }
    dis[now][now]=0;
    priority_queue<P,vector<P>,greater<P> > q;
    q.push(make_pair(0,now));
    while(q.size()){
        int z=q.top().second;
        q.pop();
        if(vis[z]) continue;
        vis[z]=true;
        for(register int i=head[z];i;i=nxt[i]){
            int y=to[i];
            if(y==z) continue;
            if(dis[now][y]>dis[now][z]+1){
                dis[now][y]=dis[now][z]+1;//权值加1,意思是
                q.push(make_pair(dis[now][y],y));
            }
        }
    }
}
inline double dfs(int mouse,int cat){
    if(visi[mouse][cat]) return dp[mouse][cat];
    if(mouse==cat){
        return 0;
    }
    else if(op[mouse][cat]==mouse||op[mouse][op[mouse][cat]]==mouse){
        return 1;
    }
    else{
        visi[mouse][cat]=true;
        // dp[mouse][cat]++;
        int p=d[mouse]+1;
        dp[mouse][cat]+=(dfs(mouse,op[mouse][op[mouse][cat]])+1)/(1.0*p);
        for(register int i=head[mouse];i;i=nxt[i]){
            int y=to[i];//老鼠跳到的位置
            dp[mouse][cat]+=(dfs(y,op[mouse][op[mouse][cat]])+1)/(1.0*p);
        }
        // cout<<dp[mouse][cat]<<endl;
        return dp[mouse][cat];
    }
}
signed main(void){
    n=read(),m=read(),cat=read(),mouse=read();
    for(register int i=1;i<=m;i++){
        register int asd=read(),jkl=read();
        add(asd,jkl),add(jkl,asd);
        d[asd]++,d[jkl]++;
    }
    for(register int i=1;i<=n;i++){
        dij(i);
    }
    for(register int i=1;i<=n;i++){//老鼠
        for(register int j=1;j<=n;j++){//猫
        if(i==j){continue;}
            int minn=INT_MAX,mindian=INT_MAX;
            for(register int k=head[j];k;k=nxt[k]){//猫跳下一个点
                int y=to[k];
                if(dis[i][y]<minn){
                    op[i][j]=y;
                    minn=dis[i][y];
                    mindian=y;
                }
                else if(dis[i][y]==minn&&y<mindian){
                    op[i][j]=y;
                }
            }
        }
        // puts("");
    }
    printf("%.3lf",dfs(mouse,cat));
    return 0;
}

调了一上午力还是没调出来🥵🥵😰😰😰😰😭😭😭


hack数据 输入

484 934
376 118
105 131
253 18
176 70
255 228
427 1
164 287
320 150
198 38
453 83
191 201
131 420
342 6
475 323
409 484
419 465
405 4
264 347
402 21
174 429
244 3
102 393
23 38
368 339
428 466
338 396
88 134
448 146
6 107
239 164
185 126
180 185
123 19
306 147
190 254
54 65
212 90
105 61
41 137
274 193
441 86
53 248
30 161
249 377
11 430
426 266
277 254
484 153
97 34
147 199
398 454
164 291
316 32
270 155
68 480
352 184
173 31
146 251
399 45
78 437
434 474
385 414
274 346
288 331
283 165
11 320
390 246
142 75
357 179
383 287
326 109
226 221
38 372
317 326
421 322
206 448
254 145
283 398
319 436
389 426
211 257
436 205
249 209
250 471
89 181
159 288
484 259
465 187
267 265
195 298
168 416
314 453
313 458
25 345
240 357
423 310
40 223
315 285
73 339
255 30
454 241
180 36
331 133
321 55
325 288
1 52
148 216
285 483
435 29
77 482
234 375
1 462
2 120
103 269
474 247
136 353
236 172
217 321
242 338
79 106
82 179
74 238
457 166
93 123
154 281
415 85
171 96
458 241
161 259
10 469
199 362
139 156
370 284
115 129
311 218
250 406
430 13
119 188
149 347
51 338
189 476
137 230
76 417
205 216
302 395
461 51
24 431
196 201
86 330
131 258
243 189
52 44
60 270
262 104
13 22
407 369
80 333
287 12
150 217
92 210
234 332
233 281
42 278
62 481
451 366
35 93
163 175
344 2
33 290
445 430
454 95
480 175
39 236
378 56
400 78
279 289
330 460
380 202
209 234
39 35
387 233
398 458
139 106
431 136
54 260
221 174
442 355
394 476
19 464
156 424
172 205
279 459
13 404
364 81
455 65
449 171
127 441
124 361
68 240
325 171
466 117
167 429
320 349
217 103
385 182
63 62
344 211
111 256
30 190
214 328
228 190
422 317
91 187
370 176
455 192
246 189
247 125
165 456
337 382
197 475
289 301
212 450
407 31
59 312
103 222
442 387
208 321
95 60
294 386
177 461
116 262
133 383
228 277
153 351
259 351
305 3
231 455
456 99
342 142
328 121
117 33
60 235
351 442
266 37
345 431
253 220
257 112
465 2
348 73
90 168
100 313
474 304
296 244
9 72
27 29
347 373
482 12
162 249
440 316
307 314
181 162
81 152
357 136
257 132
100 398
343 133
381 213
423 273
328 15
197 141
192 203
170 418
432 87
95 207
122 479
10 47
151 142
367 386
63 332
295 238
483 92
221 456
304 464
292 389
21 385
413 409
223 306
466 363
43 286
324 289
316 7
292 413
101 169
9 444
158 85
300 111
28 24
315 340
293 78
91 101
265 115
167 425
293 451
392 305
144 170
369 327
179 449
301 472
70 439
400 237
175 359
21 418
478 343
298 236
360 139
53 185
193 272
403 374
360 79
289 284
481 225
464 451
445 280
437 401
427 443
133 77
57 239
303 24
414 344
252 315
309 186
127 375
363 229
396 130
371 84
389 421
12 397
208 122
310 214
388 283
418 419
230 467
149 177
426 322
150 404
52 163
453 102
459 379
194 128
156 243
276 371
40 232
363 33
329 325
246 41
432 64
312 364
275 452
411 467
8 365
87 279
264 477
236 436
18 164
176 309
405 253
186 335
395 43
148 32
58 92
443 462
259 140
96 18
143 286
80 267
203 151
327 469
37 16
268 329
404 110
448 54
199 378
248 10
65 352
84 324
227 131
313 108
163 268
185 336
121 158
297 197
276 432
261 384
472 42
152 299
132 166
270 255
48 307
55 28
67 117
178 52
447 411
101 312
368 298
62 196
46 173
203 342
358 365
107 195
365 149
59 252
136 111
109 426
422 346
113 323
406 8
333 265
14 1
27 391
5 200
476 230
369 231
42 77
308 328
301 311
435 147
166 152
373 228
69 157
475 392
478 331
314 5
138 387
45 183
254 380
43 415
468 446
350 355
356 427
216 400
87 294
128 283
417 73
258 8
152 116
462 432
406 167
359 449
393 434
99 60
326 389
414 399
437 414
306 212
431 300
354 463
468 348
266 275
37 452
134 74
232 27
278 369
85 215
183 112
230 333
384 391
332 196
391 433
429 334
430 150
134 295
110 269
83 393
252 129
415 360
322 37
373 273
215 390
419 91
159 478
81 58
118 330
143 49
49 438
238 275
380 40
358 114
411 91
332 191
331 18
261 215
410 405
361 197
304 125
169 457
450 168
248 336
110 221
334 477
245 250
57 105
433 41
479 25
322 153
17 194
403 62
469 63
251 219
182 465
188 45
112 135
47 48
256 213
140 71
17 69
362 416
354 342
271 163
240 82
444 53
26 151
269 68
271 480
7 144
146 260
284 70
412 94
421 484
201 441
209 127
114 113
446 195
379 343
162 382
220 250
396 121
210 104
311 46
98 406
299 210
204 380
386 478
181 337
124 356
142 107
82 359
200 118
66 80
417 395
337 10
420 358
366 401
51 308
277 204
463 6
219 244
31 180
327 455
18 383
164 282
58 299
160 242
256 253
3 417
409 161
225 441
339 319
336 47
290 4
327 54
428 67
480 82
107 263
72 408
460 247
307 75
235 413
397 251
359 325
408 248
117 410
79 7
353 381
161 318
213 245
382 469
452 350
440 148
481 5
34 384
108 274
377 63
29 433
206 327
48 374
126 203
386 379
84 279
26 48
443 276
158 261
401 188
438 79
64 294
280 124
214 204
288 96
429 264
46 407
50 105
319 440
207 235
362 56
280 13
69 128
22 110
447 419
129 340
155 30
147 450
463 468
425 149
15 202
126 26
378 66
282 361
241 317
318 145
444 180
22 14
353 224
190 318
351 138
29 199
61 282
267 372
469 403
345 67
339 49
290 69
439 173
94 119
382 316
349 217
97 261
284 311
16 350
235 155
130 158
308 396
294 459
213 227
184 468
6 446
171 57
365 113
113 177
438 316
361 114
205 19
34 27
476 411
121 97
287 297
372 115
36 192
174 99
382 377
471 174
20 130
387 154
14 178
377 234
232 435
371 87
118 434
32 402
200 86
141 392
33 405
141 219
31 231
393 93
237 385
36 126
401 399
145 40
298 319
85 139
384 390
251 296
391 246
96 239
364 285
272 376
187 169
140 138
223 435
296 184
260 352
375 191
120 132
233 212
55 303
66 198
312 315
215 156
229 17
242 302
297 397
413 421
218 278
355 154
56 23
383 482
98 258
3 302
324 370
8 425
64 367
114 475
446 368
166 341
265 252
195 39
204 15
477 373
130 415
263 102
72 53
24 357
462 44
15 97
347 423
196 225
192 354
153 16
193 88
439 9
376 74
424 394
451 94
269 271
410 256
456 95
231 36
220 470
394 447
473 445
25 428
7 402
272 134
170 447
120 457
470 471
75 453
367 159
35 172
273 214
395 143
286 438
219 305
341 116
467 101
381 50
70 46
173 444
244 76
352 463
28 240
216 293
88 109
155 409
224 57
323 461
374 481
4 157
300 410
374 314
318 140
145 71
338 20
309 439
433 378
340 483
47 403
93 474
194 388
202 232
75 263
258 358
89 408
71 223
132 135
177 423
472 218
356 14
16 442
464 412
41 66
211 183
106 424
157 226
108 422
169 364
225 200
73 143
144 21
436 148
99 334
321 222
202 34
20 43
32 400
77 206
4 220
471 167
399 211
245 98
323 160
187 120
175 329
273 277
470 221
416 23
179 353
226 165
305 242
135 341
111 381
56 198
477 255
291 233
281 90
222 68
106 144
435 106
302 20
310 308
390 243
335 72
61 420
424 170
282 297
229 290
189 137
198 267
482 448
286 360
160 51
278 206
263 39
222 28
49 440
459 301
349 208
182 344
137 80
124 22
19 293
123 304
392 160
457 81
467 59
260 296
197 394
425 264
178 271
165 454
237 437
402 237
71 291
128 226
291 306
295 266
418 182
151 307
346 88
346 326
76 348
218 407
78 366
333 59
67 300
473 11
388 100
303 345
42 129
268 367
83 118
285 58
12 146
449 224
65 354
343 42
5 83
397 141
317 292
450 362
329 159
334 270
186 9
138 291
241 207
227 98
157 470
299 262
122 55
224 50
184 76
243 394
461 310
366 119
479 303
434 460
207 292
253 245
110 178
379 472
408 337
44 268
336 26
125 412
44 64
109 295
2 257
458 422
420 361
50 227
172 123
239 61
102 35
348 368
335 89
404 103

输出

12.183

实际输出

12.177

求调😭😭😭😭😭

2023/7/23 10:55
加载中...