fork download
  1. #include <iostream>
  2. #include <cstdlib>
  3. #include <cmath>
  4.  
  5. using namespace std;
  6.  
  7. int main()
  8. {
  9. int n;
  10. double x1, y1, r1, x2, y2, r2;
  11. double d,l;
  12. cin >> n;
  13. cout.setf(ios::fixed);
  14. cout.precision(2);
  15. for (int i = 0; i < n; i++)
  16. {
  17. cin >> x1; cin >> y1; cin >> r1;
  18. cin >> x2; cin >> y2; cin >> r2;
  19. d = sqrt(pow(x1 - x2, 2) + pow(y1 - y2, 2));
  20. if (r1 + r2 <= d) //okregi rozlaczne/styczne
  21. l = 0;
  22. else if (d > abs(r1 - r2) && d < r1 + r2)//okregi przecinaja sie
  23. l = r1 + r2 - d;
  24. else if (d <= abs(r1 - r2)) //jeden w drugim
  25. {
  26. if (r1 < r2)
  27. l = 2 * r1;
  28. else
  29. l = 2 * r2;
  30. }
  31. cout << l << endl;
  32. }
  33. return 0;
  34. }
Success #stdin #stdout 0s 5272KB
stdin
35
202 6638 8453
3320 6968 2432
5285 429 1486
1358 9139 2551
354 2157 1380
8331 452 1501
1176 436 6068
2203 9157 4806
9702 2186 5956
3618 2808 5684
5194 9146 9379
4476 7530 7622
9712 4485 6840
4565 29 616
4097 248 9120
66 8298 5675
4028 1468 198
4821 5586 4112
8476 8131 5561
8248 7016 7312
4512 9224 6337
8759 3012 8143
3835 6700 1678
538 5870 3400
974 5947 7606
7523 1134 1832
2396 5223 1456
3398 9381 6739
1225 3639 5738
765 9618 706
6984 1692 5773
3714 1944 1972
8709 2385 9633
6867 425 8871
4653 1052 2922
8669 2202 5586
9267 3639 546
7319 1593 5074
9101 485 2754
298 7829 3005
9179 4768 3962
2335 8053 2953
7111 6153 7647
9722 6181 403
1770 226 7454
1226 185 2345
1557 7147 9111
1368 8836 7427
9006 4825 5334
1860 6501 529
8086 1963 4489
6186 1656 784
9376 2134 8919
2094 3946 4288
5870 3859 2552
9509 2218 5514
3410 9380 4943
5351 7283 2290
7035 6131 4600
1521 6888 9865
5353 466 1830
943 439 5720
2136 5625 7719
6143 2590 2938
9133 5229 6691
9757 637 1320
3336 7860 8957
2728 1696 5918
6959 1678 6893
9134 4990 4581
stdout
4864.00
0.00
0.00
2092.74
5524.29
15232.67
648.10
5792.14
116.34
11122.00
6954.98
1678.13
1310.62
2912.00
447.33
3944.00
15814.29
4330.59
1092.00
0.00
0.00
806.00
4690.00
14838.46
0.00
1568.00
5702.94
4074.11
4375.57
8899.28
3139.92
5630.34
2640.00
8681.09
7511.68