fork(2) download
  1. #include <bits/stdc++.h>
  2. using namespace std;
  3. int h; vector<int>pos(4); vector<int>speed(4); vector<int>direct(4);
  4. float max_area=-1,min_area=-1, has_ended=0;
  5.  
  6. typedef struct {int x, y, z;} Point;
  7.  
  8. float Calculate_Area_Perimeter_Triangle(float ax, float ay, float az, float bx, float by, float bz, float cx, float cy, float cz)
  9.  
  10. {
  11. float A = sqrt((double)(bx-ax) * (bx-ax) + (by-ay) * (by-ay) + (bz-az) * (bz-az));
  12. float B = sqrt((double)(bx-cx) * (bx-cx) + (by-cy) * (by-cy) + (bz-cz) * (bz-cz));
  13. float C = sqrt((double)(ax-cx) * (ax-cx) + (ay-cy) * (ay-cy) + (az-cz) * (az-cz));
  14. float height = 0;
  15. // Heron's formula for area calculation
  16.  
  17. // area = sqrt( s * (s-a) * (s-b) * (s-c))
  18.  
  19. float s = (A + B + C) / 2;
  20. float area = sqrt( s * (s-A) * (s-B) * (s-C));
  21. // area = 1/2 * base * height
  22. // if side A is base, then height
  23. return area;
  24.  
  25. }
  26.  
  27. int areas(int curr_time)
  28. {
  29. float ax,ay,az,bx,by,bz,cx,cy,cz,dx,dy,dz;
  30. has_ended=1;
  31. //Poitn A
  32. ax=0 ; ay=0; az = max(0,min(h,pos[0]+direct[0]*speed[0]*curr_time));
  33. if(az<h && az >0) has_ended=0;
  34.  
  35. //Point B
  36. bx=h; by=0 ; bz = max(0,min(h,pos[1]+direct[1]*speed[1]*curr_time));
  37. if(bz<h && bz >0) has_ended=0;
  38.  
  39. //Point C
  40. cx=h; cy=h ; cz = max(0,min(h,pos[2]+direct[2]*speed[2]*curr_time));
  41. if(cz<h && cz >0) has_ended=0;
  42.  
  43. //Point D
  44. dx=0; dy=h ; dz = max(0,min(h,pos[3]+direct[3]*speed[3]*curr_time));
  45. if(dz<h && dz >0) has_ended=0;
  46.  
  47. float curr_area_sum = Calculate_Area_Perimeter_Triangle(ax,ay,az,bx,by,bz,cx,cy,cz) + Calculate_Area_Perimeter_Triangle(ax,ay,az,dx,dy,dz,cx,cy,cz);
  48. if (max_area==-1 || max_area<curr_area_sum) max_area=curr_area_sum;
  49. if(min_area==-1 || min_area>curr_area_sum) min_area=curr_area_sum;
  50.  
  51. return 0;
  52. }
  53.  
  54. int main() {
  55. cin>>h;
  56. cin>>pos[0]>>pos[1]>>pos[2]>>pos[3];
  57. cin>>speed[0]>>speed[1]>>speed[2]>>speed[3];
  58. char t;
  59. for(int i=0;i<4;i++)
  60. {
  61. cin>>t;
  62. if(t=='U') direct[i]=1;
  63. else direct[i]=-1;
  64. }
  65.  
  66. int curr_time =0;
  67. while(1)
  68. {
  69. areas(curr_time);
  70. if(has_ended==1)
  71. break;
  72. curr_time++;
  73. }
  74.  
  75. cout<<round(4*pow(max_area,2))<<' '<<round(4*pow(min_area,2))<<'\n';
  76. return 0;
  77. }
Success #stdin #stdout 0s 4700KB
stdin
10
5 5 5 5
1 1 1 1
U U D D
stdout
80000 40000