Advertisement
Guest User

Угощение 2001 Белорусская

a guest
Oct 6th, 2015
81
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 11.65 KB | None | 0 0
  1. #include <iostream>
  2. #include <cstdio>
  3. #include <vector>
  4. #include <set>
  5. #include <map>
  6. #include <cstdlib>
  7. #include <algorithm>
  8. #include <sstream>
  9. #include <queue>
  10. #include <stack>
  11. #include <ctime>
  12. #include <iomanip>
  13. #include <cmath>
  14.  
  15. #ifndef M_PI
  16. #define M_PI 3.14159265358979323846
  17. #endif
  18.  
  19. using namespace std;
  20.  
  21. #define pb push_back
  22. #define mp make_pair
  23. #define S second
  24. #define F first
  25.  
  26. //basic typedef
  27. typedef long long ll;
  28. typedef double ld;
  29. typedef pair<ld, ld> pld;
  30. //structs
  31. struct pt{ //point
  32.     ld x, y;
  33. };
  34.  
  35. struct ln{ //line
  36.     ld a, b, c;
  37. };
  38.  
  39. struct sg{ //segment
  40.     pt a, b;
  41. };
  42.  
  43. struct cr{ //circle
  44.     pt c;
  45.     ld r;
  46. };
  47.  
  48. typedef vector<pt> pl; //polygon
  49.  
  50. //constructors
  51. pt mpt (ld x, ld y) {
  52.     pt obj;
  53.     obj.x = x;
  54.     obj.y = y;
  55.     return obj;
  56. }
  57.  
  58. ln mln (ld a, ld b, ld c) {
  59.     ln obj;
  60.     obj.a = a;
  61.     obj.b = b;
  62.     obj.c = c;
  63.     return obj;
  64. }
  65.  
  66. sg msg (pt a, pt b) {
  67.     sg obj;
  68.     obj.a = a;
  69.     obj.b = b;
  70.     return obj;
  71. }
  72.  
  73. cr mcr (pt c, ld r) {
  74.     cr t;
  75.     t.c = c;
  76.     t.r = r;
  77.     return t;
  78. }
  79. //io tricks
  80. ostream &operator<<(ostream &os, pt const &p) {
  81.     return os << "(" << p.x << " " << p.y << ")";
  82. }
  83.  
  84. ostream &operator<<(ostream &os, sg const &s) {
  85.     return os << "{(" << s.a << ") (" << s.b << ")}";
  86. }
  87.  
  88. istream &operator>>(istream &is, pt &p) {
  89.     return is >> p.x >> p.y;
  90. }
  91.  
  92. istream &operator>>(istream &is, ln &l) {
  93.     return is >> l.a >> l.b >> l.c;
  94. }
  95.  
  96. void ny (bool x) {
  97.     if (x) cout << "YES";
  98.     else cout << "NO";
  99.     exit(0);
  100. }
  101. //consts
  102. const ld ldINF = 1e+018;
  103. const ld EPS = 1e-009;
  104. const pt Npt = mpt(ldINF, ldINF);
  105. const pld Npld = mp(ldINF, ldINF);
  106. const sg Nsg = msg(Npt, Npt);
  107. //equals
  108. bool eq (ld x, ld y) {
  109.     return fabs(x - y) < EPS;
  110. }
  111.  
  112. bool eq (ln x, ln y) {
  113.     return eq(x.a, y.a) && eq(x.b, y.b) && eq(x.c, y.c);
  114. }
  115.  
  116. bool eq (pt x, pt y) {
  117.     return eq(x.x, y.x) && eq(x.y, y.y);
  118. }
  119.  
  120. bool eq (sg x, sg y) {
  121.     return eq(x.a, y.a) && eq(x.b, y.b);
  122. }
  123.  
  124. bool eq (cr x, cr y) {
  125.     return eq(x.c, y.c) && eq(x.r, y.r);
  126. }
  127.  
  128. bool eq (pld x, pld y) {
  129.     return eq(x.F, y.F) && eq(x.S, y.S);
  130. }
  131. //Basic algos
  132. int fsign (ld x) {
  133.     if (eq(x, 0)) return 0;
  134.     if (x > 0) return 1;
  135.     return -1;
  136. }
  137.  
  138. pld solveSquare (ld a, ld b, ld c) { //ax^2 + bx + c = 0
  139.     if (eq(a, 0)) {
  140.         if (eq(b, 0)) return Npld;
  141.         pld ans;
  142.         ans.F = ans.S = (-c) / b;
  143.         return ans;
  144.     }
  145.     ld D = sqrt(b * b - 4 * a * c);
  146.     pld ans;
  147.     ans.F = (-b + D) / (2 * a);
  148.     ans.S = (-b - D) / (2 * a);
  149.     return ans;
  150. }
  151.  
  152. pld segsInsc (ld l1, ld r1, ld l2, ld r2) { //intersect of two segments
  153.     if (l1 > r1) swap(l1, r1);
  154.     if (l2 > r2) swap(l2, r2);
  155.     if (l1 > l2) {
  156.         swap(l1, l2);
  157.         swap(r1, r2);
  158.     }
  159.     if (l2 > r1) return Npld;
  160.     pld ans;
  161.     ans.F = l2;
  162.     ans.S = min(r1, r2);
  163.     return ans;
  164. }
  165.  
  166. bool into (ld x, ld l, ld r) {
  167.     if (l > r) swap(l, r);
  168.     return x >= l && x <= r;
  169. }
  170.  
  171. ld dist (pt p1, pt p2) { //Pythagoras
  172.     return sqrt((p1.x - p2.x) * (p1.x - p2.x) + (p1.y - p2.y) * (p1.y - p2.y));
  173. }
  174.  
  175. ld multVect (pt s, pt v1, pt v2) { //v1 * v2
  176.     return (v2.x - s.x) * (v1.y - s.y) - (v2.y - s.y) * (v1.x - s.x);
  177. }
  178. //line algos
  179. ln makeln (pt p1, pt p2) {
  180.     ln t;
  181.     if (!eq(p1.y, p2.y)) {
  182.         t.a = 1;
  183.         t.b = (t.a * (p1.x - p2.x)) / (p2.y - p1.y);
  184.     } else {
  185.         t.b = 1;
  186.         t.a = (t.b * (p2.y - p1.y)) / (p1.x - p2.x);
  187.     }
  188.     t.c = -(t.a * p1.x + t.b * p1.y);
  189.     return t;
  190. }
  191.  
  192. pt intersect (ln t1, ln t2) {
  193.     pt r;
  194.     if (eq(t2.a * t1.b - t2.b * t1.a, 0)) return Npt;
  195.     if (eq(t1.a, 0)) swap(t1, t2);
  196.     r.y = (t1.a * t2.c - t1.c * t2.a) / (t2.a * t1.b - t2.b * t1.a);
  197.     r.x = (t1.b * r.y + t1.c) / (-t1.a);
  198.     return r;
  199. }
  200.  
  201. pt perp (ln l, pt p) { //perpendicular
  202.     ld t = -(l.a * p.x + l.b * p.y + l.c) / (l.a * l.a + l.b * l.b);
  203.     return mpt(p.x + t * l.a, p.y + t * l.b);
  204. }
  205.  
  206. ld dist (ln l, pt p) { //perpendicular
  207.     return fabs(l.a * p.x + l.b * p.y + l.c) / sqrt(l.a * l.a + l.b * l.b);
  208. }
  209.  
  210. ln moveToPt (ln l, pt p) { //parallel line trough pt
  211.     l.c = -(l.a * p.x + l.b * p.y);
  212.     return l;
  213. }
  214.  
  215. ld findX (ln t, ld y) {
  216.     return (-t.b * y - t.c) / t.a;
  217. }
  218.  
  219. ld findY (ln t, ld x) {
  220.     return (-t.a * x - t.c) / t.b;
  221. }
  222.  
  223. int ptRels (ln l, pt p) {
  224.     return fsign(l.a * p.x + l.b * p.y + l.c);
  225. }
  226. //Areas
  227. ld triangleArea (pt p1, pt p2, pt p3) {
  228.     return fabs(multVect(p1, p2, p3)) / 2;
  229. }
  230. //segs algos
  231. ln makeln (sg s) {
  232.     return makeln(s.a, s.b);
  233. }
  234.  
  235. int ptRels (sg s, pt p) {
  236.     return fsign(multVect(s.a, s.b, p));
  237. }
  238.  
  239. pt intersect (sg s, pt p) {
  240.     if (into(p.x, s.a.x, s.b.x) && into(p.y, s.a.y, s.b.y) && ptRels(s, p) == 0) return p;
  241.     return Npt;
  242. }
  243.  
  244. sg intersect2 (sg x, sg y) {
  245.     if (eq(x.a, x.b)) {
  246.         if (eq(y.a, y.b))
  247.         if (eq(x, y)) return x;
  248.         else return Nsg;
  249.         pt p = intersect(y, x.a);
  250.         if (eq(p, Npt)) return Nsg;
  251.         return msg(p, p);
  252.     }
  253.     if (eq(y.a, y.b)) {
  254.         swap(x, y);
  255.         pt p = intersect(y, x.a);
  256.         if (eq(p, Npt)) return Nsg;
  257.         return msg(p, p);
  258.     }
  259.     ln l1, l2;
  260.     l1 = makeln(x);
  261.     l2 = makeln(y);
  262.     if (eq(l1, l2)) {
  263.         if (eq(l1.b, 0)) {
  264.             pld f = segsInsc(x.a.y, x.b.y, y.a.y, y.b.y);
  265.             if (f == Npld) return Nsg;
  266.             return msg(mpt(findX(l1, f.F), f.F), mpt(findX(l1, f.S), f.S));
  267.         }
  268.         pld f = segsInsc(x.a.x, x.b.x, y.a.x, y.b.x);
  269.         if (f == Npld) return Nsg;
  270.         return msg(mpt(f.F, findY(l1, f.F)), mpt(f.S, findY(l1, f.S)));
  271.     }
  272.     pt p = intersect(l1, l2);
  273.     if (eq(p, Npt))
  274.         return Nsg;
  275.     if (into(p.x, x.a.x, x.b.x) && into(p.y, x.a.y, x.b.y) && into(p.x, y.a.x, y.b.x) && into(p.y, y.a.y, y.b.y))
  276.         return msg(p, p);
  277.     return Nsg;
  278. }
  279.  
  280. ld dist (sg s, pt p) {
  281.     pt x = perp(makeln(s), p);
  282.     if (eq(intersect(s, x), Npt))
  283.         return min(dist(s.a, p), dist(s.b, p));
  284.     return dist(x, p);
  285. }
  286. //Rays
  287. bool isOnRay (pt s, pt d, pt t) {
  288.     return eq(s, t) || !ptRels(msg(s, d), t) && fsign(d.x - s.x) == fsign(t.x - s.x) && fsign(d.y - s.y) == fsign(t.y - s.y);
  289. }
  290.  
  291. ld distRay (pt s, pt d, pt t) {
  292.     pt px = perp(makeln(s, d), t);
  293.     if (!isOnRay(s, d, px)) px = s;
  294.     return dist(t, px);
  295. }
  296.  
  297. ld fangle (pt p) {
  298.     ld a = atan(p.y / p.x);
  299.     if (p.y == 0 && p.x > 0) return 0;
  300.     if (p.x < 0) return M_PI + a;
  301.     if (p.y > 0) return a;
  302.     return 2 * M_PI + a;
  303. }
  304.  
  305. ld fangle (pt p, pt a, pt b) {
  306.     a.x -= p.x;
  307.     a.y -= p.y;
  308.     b.x -= p.x;
  309.     b.y -= p.y;
  310.     ld x = fabs(fangle(a) - fangle(b));
  311.     return min(x, 2 * M_PI - x);
  312. }
  313. //Polygons
  314. ld polygonArea (pl p) {
  315.     ld s = 0;
  316.     pt last = p.back();
  317.     for (int i = 0; i < p.size(); i++) {
  318.         s += (p[i].y + last.y) * (p[i].x - last.x);
  319.         last = p[i];
  320.     }
  321.     return fabs(s / 2);
  322. }
  323.  
  324. ll fpts (pl p) {
  325.     pt last = p.back();
  326.     ll pts = 0;
  327.     for (int i = 0; i < p.size(); i++) {
  328.         ll x = round(fabs(p[i].x - last.x));
  329.         ll y = round(fabs(p[i].y - last.y));
  330.         pts += __gcd(x, y);
  331.         last = p[i];
  332.     }
  333.     return pts;
  334. }
  335.  
  336. ll pickTheorem (pl p) {
  337.     return (round(polygonArea(p)) * 2 - fpts(p) + 2) / 2;
  338. }
  339. //Circles
  340. sg intersect(cr c, ln l) {
  341.     if (!eq(l.a, 0)) {
  342.         ld ta, tb, tc;
  343.         ta = (l.b * l.b / l.a / l.a) + 1;
  344.         tb = 2 * l.b * l.c / l.a / l.a;
  345.         tb += 2 * l.b * c.c.x / l.a;
  346.         tb -= 2 * c.c.y;
  347.         tc = c.c.x * c.c.x;
  348.         tc += c.c.y * c.c.y;
  349.         tc += 2 * l.c * c.c.x / l.a;
  350.         tc += l.c * l.c / l.a / l.a;
  351.         tc -= c.r * c.r;
  352.         pld ans = solveSquare(ta, tb, tc);
  353.         if (eq(ans, Npld)) return Nsg;
  354.         ld x0 = (-l.b * ans.F - l.c) / l.a;
  355.         ld x1 = (-l.b * ans.S - l.c) / l.a;
  356.         return msg(mpt(x0, ans.F), mpt(x1, ans.S));
  357.     }
  358.     ld y = (-l.c) / l.b;
  359.     ld ta, tb, tc;
  360.     ta = 1;
  361.     tb = -2 * c.c.x;
  362.     tc = c.c.x * c.c.x + y * y + c.c.y * c.c.y - 2 * y * c.c.y - c.r * c.r;
  363.     pld ans = solveSquare(ta, tb, tc);
  364.     if (eq(ans, Npld)) return Nsg;
  365.     return msg(mpt(ans.F, y), mpt(ans.S, y));
  366. }
  367.  
  368. sg intersect (cr c1, cr c2) {
  369.     return intersect(c1, mln(-2 * c2.c.x, -2 * c2.c.y,
  370.                              c2.c.x * c2.c.x + c2.c.y * c2.c.y + c1.r * c1.r - c2.r * c2.r));
  371. }
  372. //Very specific algos
  373. ln rot90 (pt p1, pt p2, pt p) {
  374.     ln l = makeln(p1, p2);
  375.     l = makeln(mpt(0, 0), mpt(l.a, l.b));
  376.     return moveToPt(l, p);
  377. }
  378.  
  379. pt ptRay (pt p1, pt p2, ld l) {
  380.     sg s = intersect(mcr(p1, l), makeln(p1, p2));
  381.     if (isOnRay(p1, p2, s.a)) return s.a;
  382.     return s.b;
  383. }
  384. //Convex hull
  385. bool cmp (pt a, pt b) {
  386.     return a.x < b.x || a.x == b.x && a.y < b.y;
  387. }
  388.  
  389. pl convexHull (pl a) {
  390.     if (a.size() == 1) return a;
  391.     sort(a.begin(), a.end(), &cmp);
  392.     sg line = msg(a[0], a.back());
  393.     pl up, down;
  394.     up.pb(a[0]);
  395.     down.pb(a[0]);
  396.     for (int i = 1; i < a.size(); i++) {
  397.         if (ptRels(line, a[i]) <= 0) {
  398.             while (up.size() >= 2 && ptRels(msg(up[up.size() - 2], up.back()), a[i]) <= 0)
  399.                 up.pop_back();
  400.             up.pb(a[i]);
  401.         }
  402.         if (ptRels(line, a[i]) >= 0) {
  403.             while (down.size() >= 2 && ptRels(msg(down[down.size() - 2], down.back()), a[i]) >= 0)
  404.                 down.pop_back();
  405.             down.pb(a[i]);
  406.         }
  407.     }
  408.     for (int i = down.size() - 2; i > 0; --i) up.pb(down[i]);
  409.     if (up.size() == 2 && eq(up[0], up[1]))
  410.             up.pop_back();
  411.     return up;
  412. }
  413.  
  414. ld calc (ld px, vector<pl> &t, pt &dl) {
  415.     sg g = msg(mpt(px, 0), mpt(px + dl.x, dl.y));
  416.     ln w = makeln(g);
  417.     ld s = 0;
  418.     for (int i = 0; i < t.size(); i++) {
  419.         if (ptRels(g, t[i][2]) == -1) {
  420.             s += polygonArea(t[i]);
  421.             continue;
  422.         }
  423.         if (ptRels(g, t[i][0]) == 1) {
  424.             continue;
  425.         }
  426.         int pos1 = ptRels(g, t[i][1]);
  427.         int pos2 = ptRels(g, t[i][3]);
  428.         pl inAns;
  429.         inAns.pb(t[i][0]);
  430.         if (pos1 == 0) {
  431.             inAns.pb(t[i][1]);
  432.         } else if (pos1 == -1) {
  433.             inAns.pb(t[i][1]);
  434.             inAns.pb(intersect(w, makeln(t[i][1], t[i][2])));
  435.         } else {
  436.             inAns.pb(intersect(w, makeln(t[i][0], t[i][1])));
  437.         }
  438.         if (pos2 == 0) {
  439.             inAns.pb(t[i][3]);
  440.         } else if (pos2 == 1) {
  441.             inAns.pb(intersect(w, makeln(t[i][0], t[i][3])));
  442.         } else {
  443.             inAns.pb(intersect(w, makeln(t[i][3], t[i][2])));
  444.             inAns.pb(t[i][3]);
  445.         }
  446.         s += polygonArea(inAns);
  447.     }
  448.     return s;
  449. }
  450.  
  451. int main() {
  452.     ios_base::sync_with_stdio(0);
  453. #ifdef LOCAL
  454.     freopen("input.txt", "r", stdin);
  455.     freopen("output.txt", "w", stdout);
  456. #else
  457.     freopen("sausage.in", "r", stdin);
  458.     freopen("sausage.out", "w", stdout);
  459. #endif
  460.     int n;
  461.     cin >> n;
  462.     if (n == 1) return 0;
  463.     ld f;
  464.     cin >> f;
  465.     f = (f / 180) * M_PI;
  466.     pt e = mpt(1, tan(f));
  467.     int k;
  468.     cin >> k;
  469.     vector<pl> v;
  470.     ld br = 0;
  471.     ld total = 0;
  472.     for (int i = 0; i < k; i++) {
  473.         ld y, x;
  474.         cin >> y >> x;
  475.         total += x * y;
  476.         y /= 2;
  477.         pl t;
  478.         t.pb(mpt(br, y));
  479.         t.pb(mpt(br + x, y));
  480.         t.pb(mpt(br + x, -y));
  481.         t.pb(mpt(br, -y));
  482.         v.pb(t);
  483.         br += x;
  484.     }
  485.     cout << fixed << setprecision(2);
  486.     for (int i = 1; i < n; i++) {
  487.         ld cur = total / n;
  488.         cur *= i;
  489.         ld l = -1e+09;
  490.         ld r = +1e+09;
  491.         ld ans = -1;
  492.         for (int step = 0; step < 400; step++) {
  493.             ld mid = (l + r) / 2;
  494.             if (calc(mid, v, e) >= cur) {
  495.                 ans = mid;
  496.                 r = mid;
  497.             } else {
  498.                 l = mid;
  499.             }
  500.         }
  501.         cout << ans << endl;
  502.     }
  503.     return 0;
  504. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement