Advertisement
double_trouble

пылесос

Nov 19th, 2015
82
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 7.35 KB | None | 0 0
  1. #define _CRT_SECURE_NO_WARNINGS
  2. #include <iostream>
  3. #include <cstdio>
  4. #include <vector>
  5. #include <cmath>
  6. #include <string>
  7. #include <algorithm>
  8. #include <string>
  9. #include <deque>
  10. #include <iomanip>
  11. #include <map>
  12.  
  13. #define F first
  14. #define S second
  15.  
  16. using namespace std;
  17.  
  18. const long double eps = 0.0000005;
  19. const long double eps1 = 1e-5;
  20. const long double pi = 3.1415926535897932;
  21.  
  22. struct point
  23. {
  24.     double x;
  25.     double y;
  26.     double v;
  27.     point()
  28.     {
  29.         x = 0.0;
  30.         y = 0.0;
  31.     }
  32.     point(double _x, double _y)
  33.     {
  34.         x = _x;
  35.         y = _y;
  36.     }
  37. };
  38.  
  39. struct line
  40. {
  41.     long double a;
  42.     long double b;
  43.     long double c;
  44.     line()
  45.     {
  46.         a = 0.0;
  47.         b = 0.0;
  48.         c = 0.0;
  49.     }
  50.     line(point _a, point _b)
  51.     {
  52.         a = _b.y - _a.y;
  53.         b = _a.x - _b.x;
  54.         c = b * _a.y - a * _a.x;
  55.     }
  56. };
  57.  
  58. vector < point > d;
  59. double r;
  60. point a, b;
  61. map < point,vector < pair < double, point > > > g;
  62. point c[4];
  63.  
  64. point operator+(point a, point b)
  65. {
  66.     return point(a.x + b.x, a.y + b.y);
  67. }
  68.  
  69. point operator-(point a, point b)
  70. {
  71.     return point(a.x - b.x, a.y - b.y);
  72. }
  73.  
  74. point operator*(point a, long double k)
  75. {
  76.     return point(a.x * k, a.y * k);
  77. }
  78.  
  79. point operator/(point a, long double k)
  80. {
  81.     return point(a.x / k, a.y / k);
  82. }
  83.  
  84. bool operator<(const point& a, const point& b)
  85. {
  86.     if (a.x - b.x < -eps || (fabs(a.x - b.x) < eps && a.y - b.y < -eps))
  87.         return true;
  88.     return false;
  89. }
  90.  
  91. bool operator>(const point& a, const point& b)
  92. {
  93.     if (a.x  - b.x > eps || (fabs(a.x - b.x) < eps && a.y - b.y > eps))
  94.         return true;
  95.     return false;
  96. }
  97.  
  98. bool operator==(const point& a, const point& b)
  99. {
  100.     if (fabs(a.x - b.x) < eps && fabs(a.y - b.y) < eps)
  101.         return true;
  102.     return false;
  103. }
  104.  
  105. long double scal(point a, point b)
  106. {
  107.     return a.x * b.x + a.y * b.y;
  108. }
  109.  
  110. long double vect(point a, point b)
  111. {
  112.     return a.x * b.y - a.y * b.x;
  113. }
  114.  
  115. long double dist(point a, point b)
  116. {
  117.     return sqrt(scal(a - b, a - b));
  118. }
  119.  
  120. point norm(point a)
  121. {
  122.     return a / sqrt(scal(a, a));
  123. }
  124.  
  125. void cross(point o1, double r1, point o2, double r2, point &c1, point &c2)
  126. {
  127.     double t = dist(o1, o2);
  128.     point f = o2 - o1;
  129.     f = norm(f);
  130.     double h = r1 * r2 / t;
  131.     double l = sqrt(r1 * r1 - h * h);
  132.     f = f * l;
  133.     point p = o1 + f;
  134.     point n = point(-f.y, f.x);
  135.     n = norm(n);
  136.     n = n * h;
  137.     c1 = p + n;
  138.     c2 = p - n;
  139. }
  140.  
  141. double dist(point p, line l)
  142. {
  143.     return abs(l.a * p.x + l.b * p.y + l.c) / sqrt(l.a * l.a + l.b * l.b);
  144. }
  145.  
  146. int crossring(line l, point p)
  147. {
  148.     if ((dist(p, l) - r) < -eps)
  149.         return 2;
  150.     return 1;
  151. }
  152.  
  153. void parkas(point o1, point o2, point &c1, point &c2, point c3, point c4)
  154. {
  155.     point v = o2 - o1;
  156.     point perp = norm(point(-v.y, v.x)) * r;
  157.     c1 = o1 + perp;
  158.     c2 = o1 - perp;
  159.     c3 = o2 + perp;
  160.     c4 = o2 - perp;
  161. }
  162.  
  163. int main()
  164. {
  165.     ios_base::sync_with_stdio(0);
  166.     freopen("input.txt", "r", stdin);
  167.     //      freopen("output.txt", "w", stdout);
  168.  
  169.     double x, y;
  170.     cin >> x >> y >> r;
  171.    
  172.     a = point(x, y);
  173.     cin >> x >> y;
  174.     b = point(x, y);
  175.  
  176.     for (int i = 0; i < 3; i++)
  177.     {
  178.         cin >> x >> y;
  179.         d.push_back(point(x, y));
  180.     }
  181.  
  182.     double rr;
  183.     for (int i = 0; i < 3; i++)
  184.     {
  185.         rr = dist(a, d[i]);
  186.  
  187.         rr = sqrt(rr * rr - r * r);
  188.         point c1, c2;
  189.         cross(a, rr, d[i], r, c1, c2);
  190.         bool f = true;
  191.         for (int j = 0; j < 3; j++)
  192.         {
  193.             if (crossring(line(a, c1), d[j]) == 2)
  194.             {
  195.                 f = false;
  196.                 break;
  197.             }
  198.         }
  199.         if (f)
  200.         {
  201.             g[a].push_back(make_pair(dist(a, c1), c1));
  202.             //cout << c1.x << " " << c1.y << endl;
  203.             g[c1].push_back(make_pair(dist(a, c1), a));
  204.         }
  205.  
  206.         f = true;
  207.         for (int j = 0; j < 3; j++)
  208.         {
  209.             if (crossring(line(a, c2), d[j]) == 2)
  210.             {
  211.                 f = false;
  212.                 break;
  213.             }
  214.         }
  215.         if (f)
  216.         {
  217.             g[a].push_back(make_pair(dist(a, c2), c2));
  218.             //cout << c2.x << " " << c2.y << endl;
  219.             g[c2].push_back(make_pair(dist(a, c2), a));
  220.         }
  221.  
  222.         double ll = r * acos(1 - dist(c1, c2) * dist(c1, c2) / (2 * r * r));
  223.         g[c1].push_back(make_pair(ll, c2));
  224.         g[c2].push_back(make_pair(ll, c1));
  225.     }
  226.  
  227.     for (int i = 0; i < 3; i++)
  228.     {
  229.         rr = dist(b, d[i]);
  230.  
  231.         rr = sqrt(rr * rr - r * r);
  232.         point c1, c2;
  233.         cross(b, rr, d[i], r, c1, c2);
  234.         bool f = true;
  235.         for (int j = 0; j < 3; j++)
  236.         {
  237.             if (crossring(line(b, c1), d[j]) == 2)
  238.             {
  239.                 f = false;
  240.                 break;
  241.             }
  242.         }
  243.         if (f)
  244.         {
  245.             g[b].push_back(make_pair(dist(b, c1), c1));
  246.             //cout << c1.x << " " << c1.y << endl;
  247.             g[c1].push_back(make_pair(dist(b, c1), b));
  248.         }
  249.  
  250.         f = true;
  251.         for (int j = 0; j < 3; j++)
  252.         {
  253.             if (crossring(line(b, c2), d[j]) == 2)
  254.             {
  255.                 f = false;
  256.                 break;
  257.             }
  258.         }
  259.         if (f)
  260.         {
  261.             g[b].push_back(make_pair(dist(b, c2), c2));
  262.             //cout << c2.x << " " << c2.y << endl;
  263.             g[c2].push_back(make_pair(dist(b, c2), b));
  264.         }
  265.  
  266.         double ll = r * acos(1 - dist(c1, c2) * dist(c1, c2) / (2 * r * r));
  267.         g[c1].push_back(make_pair(ll, c2));
  268.         g[c2].push_back(make_pair(ll, c1));
  269.     }
  270.  
  271.     for (int i = 0; i < 2; i++)
  272.         for (int j = i + 1; j < 3; j++)
  273.         {
  274.             point o1 = d[i], o2 = d[j];
  275.             point v = o2 - o1;
  276.             v = v / 2;
  277.             point c1, c2, c3, c4;
  278.             double rr = sqrt(dist(v, o1) * dist(v, o1) - r * r);
  279.             cross(v, rr, o1, r, c[0], c[1]);
  280.             cross(v, rr, o2, r, c[2], c[3]);
  281.             /*c[0] = c1;
  282.             c[1] = c2;
  283.             c[2] = c3;
  284.             c[3] = c4;*/
  285.             for (int l = 0; l < 3; l++)
  286.             {
  287.                 for (int k = l + 1; k < 4; k++)
  288.                 {
  289.                     bool f = true;
  290.                     for (int h = 0; h < 3; h++)
  291.                     {
  292.                         if (crossring(line(c[l], c[k]), d[j]) == 2)
  293.                         {
  294.                             f = false;
  295.                             break;
  296.                         }
  297.                     }
  298.                     if (f)
  299.                     {
  300.                         g[c[l]].push_back(make_pair(dist(c[l], c[k]), c[k]));
  301.                         //cout << c1.x << " " << c1.y << endl;
  302.                         g[c[k]].push_back(make_pair(dist(c[l], c[k]), c[l]));
  303.                     }          
  304.                 }
  305.             }
  306.  
  307.             double ll = r * acos(1 - dist(c[0], c[1]) * dist(c[0], c[1]) / (2 * r * r));
  308.             g[c[0]].push_back(make_pair(ll, c[1]));
  309.             g[c[1]].push_back(make_pair(ll, c[0]));
  310.  
  311.             ll = r * acos(1 - dist(c[2], c[3]) * dist(c[2], c[3]) / (2 * r * r));
  312.             g[c[2]].push_back(make_pair(ll, c[3]));
  313.             g[c[3]].push_back(make_pair(ll, c[2]));
  314.         }
  315.     for (int i = 0; i < 2; i++)
  316.         for (int j = i + 1; j < 3; j++)
  317.         {
  318.             point o1 = d[i], o2 = d[j];
  319.             point c1, c2, c3, c4;
  320.            
  321.             parkas(o1, o2, c[0], c[1], c[2], c[3]);
  322.  
  323.             /*c[0] = c1;
  324.             c[1] = c2;
  325.             c[2] = c3;
  326.             c[3] = c4;*/
  327.             for (int l = 0; l < 3; l++)
  328.             {
  329.                 for (int k = l + 1; k < 4; k++)
  330.                 {
  331.                     bool f = true;
  332.                     for (int h = 0; h < 3; h++)
  333.                     {
  334.                         if (crossring(line(c[l], c[k]), d[j]) == 2)
  335.                         {
  336.                             f = false;
  337.                             break;
  338.                         }
  339.                     }
  340.                     if (f)
  341.                     {
  342.                         g[c[l]].push_back(make_pair(dist(c[l], c[k]), c[k]));
  343.                         //cout << c1.x << " " << c1.y << endl;
  344.                         g[c[k]].push_back(make_pair(dist(c[l], c[k]), c[l]));
  345.                     }
  346.                 }
  347.             }
  348.  
  349.             double ll = r * acos(1 - dist(c[0], c[1]) * dist(c[0], c[1]) / (2 * r * r));
  350.             g[c[0]].push_back(make_pair(ll, c[1]));
  351.             g[c[1]].push_back(make_pair(ll, c[0]));
  352.  
  353.             ll = r * acos(1 - dist(c[2], c[3]) * dist(c[2], c[3]) / (2 * r * r));
  354.             g[c[2]].push_back(make_pair(ll, c[3]));
  355.             g[c[3]].push_back(make_pair(ll, c[2]));
  356.         }
  357.  
  358.     bool f = true;
  359.     for (int i = 0; i < 3; i++)
  360.     {
  361.         if (crossring(line(a, b), d[i]) == 2)
  362.         {
  363.             f = false;
  364.             break;
  365.         }
  366.     }
  367.     if (f)
  368.     {
  369.         g[a].push_back(make_pair(dist(a, b), b));
  370.         //cout << c1.x << " " << c1.y << endl;
  371.         g[b].push_back(make_pair(dist(a, b),a));
  372.     }
  373.  
  374.     cout << g.size() << endl;
  375.  
  376.     for(map < point, vector < pair < double, point > > >::iterator ii = g.begin(); ii != g.end(); ii++)
  377.     {
  378.        
  379.  
  380.     }
  381.  
  382.     return 0;
  383. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement