dansuse's blog

By dansuse, history, 8 years ago, In English

This is the problem link : Problem-681E

i could not understand some part of the code in the tutorial in here the tutorial

and this is the code that i read in the tutorial the code

this is from line 45 — 49

        double angL, angR, ang;
        double angM = atan2(y - y0, x - x0);
        if (angM < 0) {
            angM += 2 * PI;
        }

from the problem Note, i modified the picture to spot "double angM"

am i right ? if i am right, why the code have to add (2 * PI), if (angM < 0)?

this is from line 51 — 56

        double tLen = sqrt(d * d - 1.0 * r * r);
        if (tLen < r0 + eps) {
            ang = asin(r / d);
        } else {
            ang = acos((d * d + r0 * r0 - 1.0 * r * r) / (2 * d * r0));
        }

this is for "double ang"  am i spot "double ang" right ?

this is from line 58 — 74

        angL = angM - ang;
        angR = angM + ang;
 
        if (angL < 0) {
            a.push_back(make_pair(angL + 2 * PI, 1));
            a.push_back(make_pair(2 * PI, -1));
            a.push_back(make_pair(0.0, 1));
            a.push_back(make_pair(angR, -1));
        } else if (angR > 2 * PI) {
            a.push_back(make_pair(angL, 1));
            a.push_back(make_pair(2 * PI, -1));
            a.push_back(make_pair(0.0, 1));
            a.push_back(make_pair(angR - 2 * PI, -1));
        } else {
            a.push_back(make_pair(angL, 1));
            a.push_back(make_pair(angR, -1));
        }

what is this code doing? What is the use of "double angL, angR, angM, ang" in the code?

this is from line 77 — 92

sort(a.begin(), a.end());
 
    double last = 0;
    int c = 0;
    double ans = 0;
 
    for (auto& p : a) {
        if (c > 0) {
            ans += p.first - last;
        }
        c += p.second;
        last = p.first;
    }
 
    ans /= 2 * PI;
    printf("%.11f", ans);

and i could not understand this one too. Could some explain all of this in a simple way? cause i'm still new in geometry problem.

If there is some resource or concept that related to this problem, please share it

Please help me...

NB : Sorry for my bad english

Full text and comments »

  • Vote: I like it
  • +3
  • Vote: I do not like it