ENG  RUSTimus Online Judge
Online Judge
Problems
Authors
Online contests
About Online Judge
Frequently asked questions
Site news
Webboard
Links
Problem set
Submit solution
Judge status
Guide
Register
Update your info
Authors ranklist
Current contest
Scheduled contests
Past contests
Rules
back to board

Discussion of Problem 1020. Rope

Why I got WA4???
Posted by ONU_Antananarivu 18 Aug 2010 21:12

struct Point
{
    double x;
    double y;
    double ac;
};

double Len(Point p1, Point p2)
{
    return sqrt((p1.x - p2.x) * (p1.x - p2.x) + (p1.y - p2.y) * (p1.y - p2.y));
}

int main()
{
    int n, r;

    cin >> n >> r;

    Point* pt = new Point [n];

    Point ser;

    ser.x = 0;
    ser.y = 0;

    for(int i = 0; i < n; i++)
    {
        cin >> pt[i].x >> pt[i].y;

        ser.x += pt[i].x;
        ser.y += pt[i].y;
    }

    ser.x /= n;
    ser.y /= n;

    double pi = acos(-1.0);

    for(int i = 0; i < n; i++)
    {
        pt[i].x -= ser.x;
        pt[i].y -= ser.y;

        pt[i].ac = atan(fabs(pt[i].y) / fabs(pt[i].x));
        if(pt[i].y > 0 && pt[i].x < 0)
            pt[i].ac += pi / 2;
        else if(pt[i].y < 0 && pt[i].x < 0)
            pt[i].ac += pi;
        else if(pt[i].y < 0 && pt[i].x > 0)
            pt[i].ac += 3 * pi / 2;
    }

    Point tmp;

    for(int i = 0; i < n; i++)
    {
        for(int j = n - 1; j > i; j--)
        {
            if(pt[j-1].ac > pt[j].ac)
            {
                tmp = pt[j-1];
                pt[j-1] = pt[j];
                pt[j] = tmp;
            }
        }
    }

    double ans = 0;

    for(int i = 0; i < n-1; i++)
    {
        ans += Len(pt[i], pt[i+1]);
    }

    ans += Len(pt[0], pt[n-1]);

    ans +=  2 * acos(-1.0) * r;

    printf("%.2f\n", ans);

    return 0;
}
Re: Why I got WA4???
Posted by Andrew Hoffmann aka SKYDOS [Vladimir SU] 18 Aug 2010 22:58
2*PI*r + sum{dist beetwen points clockwise/counterwise}
Re: Why I got WA4???
Posted by AlexandrPlusnin 24 Aug 2011 16:42
R should be a double type, not integer.