Guest User

Untitled

a guest
Feb 18th, 2018
70
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.03 KB | None | 0 0
  1. #include <iostream>
  2. #include <vector>
  3. #include <cmath>
  4. #include <string.h>
  5. using namespace std;
  6.  
  7. typedef vector<double> vd;
  8.  
  9. double dist(double p1[], double p2[]) {
  10. return sqrt((p1[0] - p2[0])*(p1[0] - p2[0]) + (p1[1] - p2[1])*(p1[1] - p2[1]));
  11. }
  12.  
  13. double cons[] = {(2*M_PI)/double(12), (2*M_PI)/double(60)};
  14.  
  15. double cross(double p1[], double p2[]) {
  16. return p1[0]*p2[1] - p1[1]*p2[0];
  17. }
  18.  
  19. double area(int h, int m, int s) {
  20. double p1[] = {3*sin(h*cons[0]), 3*cos(h*cons[0])};
  21. double p2[] = {4*sin(m*cons[1]), 4*cos(m*cons[1])};
  22. double p3[] = {5*sin(s*cons[1]), 5*cos(s*cons[1])};
  23. if (cross(p1,p2) <= 0.0001 and cross(p3,p1) <= 0.0001) return 0;
  24.  
  25. double c1 = dist(p1, p2), c2 = dist(p2, p3), c3 = dist(p3, p1);
  26.  
  27. double a = (c1 + c2 + c3)/2;
  28. if (h == 1 and m == 35 and s == 5) {
  29. cout << p1[0] << " " << p1[1] << endl;
  30. cout << p2[0] << " " << p2[1] << endl;
  31. cout << p3[0] << " " << p3[1] << endl;
  32. cout << c1 << " " << c2 << " " << c3 << " " << a << endl;
  33. cout << sqrt(a*(a-c1)*(a-c2)*(a-c3)) << endl;
  34.  
  35. }
  36. return sqrt(a*(a - c1)*(a-c2)*(a-c3));
  37. }
  38.  
  39. double* it;
  40. int h;
  41.  
  42. void start(int n) {
  43. h = 1;
  44. while (h < 2*n) h *= 2;
  45. it = new double[h];
  46. memset(it, 0, sizeof(it));
  47. }
  48.  
  49. void insert(double n, int i) {
  50. it[h/2 + i] = n;
  51. for (int j = (h/2 + i)/2; j > 0; j /= 2) it[j] = max(it[2*j], it[2*j + 1]);
  52. }
  53.  
  54. double maxi(int i, int j, int a = 1, int ai = 0, int aj = h/2-1) {
  55. int m = (ai + aj)/2;
  56. if (i <= ai and aj <= j) return it[a];
  57. if (i > aj or j < ai) return 0;
  58. return max(maxi(i, j, 2*a, ai, m), maxi(i, j, 2*a + 1, m + 1, aj));
  59. }
  60.  
  61. int main() {
  62. cout.setf(ios::fixed);
  63. cout.precision(3);
  64.  
  65. vd aux(12*3600 + 60*60 + 60);
  66. for (int i = 0; i < 12; ++i) for (int j = 0; j < 60; ++j) for (int k = 0; k < 60; ++k)
  67. aux[i*3600 + 60*j + k] = area(i,j,k);
  68. start(aux.size());
  69. for (int i = 0; i < aux.size(); ++i) insert(aux[i], i);
  70.  
  71. int h1, h2, m1, m2, s1, s2; char c;
  72. while (cin>>h1>>c>>m1>>c>>s1>>h2>>c>>m2>>c>>s2)
  73. cout << maxi(h1*3600 + m1*60 + s1,h2*3600 + m2*60 + s2) << endl;
  74. }
Add Comment
Please, Sign In to add comment