Advertisement
Saleh127

Light oj(LO) 1240

Feb 27th, 2021
253
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.09 KB | None | 0 0
  1. #include <bits/stdc++.h>
  2. using namespace std;
  3. #define ll long long
  4. #define test int t; cin>>t; for(int cs=1;cs<=t;cs++)
  5. struct cordinate
  6. {
  7. double x,y,z;
  8. };
  9.  
  10.  
  11. cordinate a[3];
  12.  
  13. double distance(cordinate p, cordinate q)
  14. {
  15. return sqrt((p.x-q.x)*(p.x-q.x)+(p.y-q.y)*(p.y-q.y)+(p.z-q.z)*(p.z-q.z));
  16. }
  17.  
  18. double ternary()
  19. {
  20.  
  21. cordinate b,c;
  22.  
  23. ll r=100;
  24.  
  25. while(r--)
  26. {
  27. b.x=(2*a[0].x+a[1].x)/3.00;
  28. c.x=(a[0].x+2*a[1].x)/3.00;
  29.  
  30. b.y=(2*a[0].y+a[1].y)/3.00;
  31. c.y=(a[0].y+2*a[1].y)/3.00;
  32.  
  33. b.z=(2*a[0].z+a[1].z)/3.00;
  34. c.z=(a[0].z+2*a[1].z)/3.00;
  35.  
  36. if(distance(b,a[2])>distance(c,a[2]))
  37. {
  38. a[0]=b;
  39. }
  40. else a[1]=c;
  41.  
  42. }
  43. return (distance(b,a[2])+distance(c,a[2]))/2.00;
  44.  
  45. }
  46.  
  47. int main()
  48. {
  49. ios_base::sync_with_stdio(0);
  50. cin.tie(0);cout.tie(0);
  51.  
  52. test
  53. {
  54. ll i,j,k;
  55. for(i=0;i<3;i++)
  56. {
  57. cin>>a[i].x>>a[i].y>>a[i].z;
  58. }
  59.  
  60. cout<<"Case "<<cs<<": "<<fixed<<setprecision(10)<<ternary()<<endl;
  61.  
  62. }
  63.  
  64. return 0;
  65. }
  66.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement