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

Wrong Answer. Help
Posted by Afli 26 Apr 2012 15:50
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <math.h>
#include <iomanip>

using namespace std;

int main()
{
    setlocale (LC_ALL, "Russian");
    int N;
    double R;
    const double PI = acos(-1.0);
    cin >> N >> R;
    if((N < 1) || (N > 100)) exit(0);
    if(R<=0) exit(0);

    double a[101][2];

    for(int i = 0; i < N; i++)
    {
        for(int j = 0; j < 2; j++)
        {
            cin >> a[i][j];
        }
    }
    a[N][0] = a[0][0];
    a[N][1] = a[0][1];
    a[N+1][0] = a[1][0];
    a[N+1][1] = a[0][1];
    a[N+2][0] = a[2][0];
    a[N+2][1] = a[2][1];

    double dLength = 0.0,
           dSide1,
           dSide2,
           dSide3,
           dCurve,
           alpha;
    for(int i = 0; i < N; i++)
    {
        dSide1 = 0.0;
        dSide2 = 0.0;
        dSide3 = 0.0;
        dCurve = 0.0;
        for(int j = 0; j < 2; j++)
        {
            dSide1 += (a[i][j] - a[i+1][j])*(a[i][j] - a[i+1][j]);
            dSide2 += (a[i+1][j] - a[i+2][j])*(a[i+1][j] - a[i+2][j]);
            dSide3 += (a[i][j] - a[i+2][j])*(a[i][j] - a[i+2][j]);
        }
        dSide1 = sqrt(dSide1);
        dSide2 = sqrt(dSide2);
        dSide3 = sqrt(dSide3);
        alpha = (dSide3*dSide3 - (dSide1*dSide1 + dSide2*dSide2)) / (-2*dSide1*dSide2);
        alpha = PI / 2 - alpha;
        alpha = alpha * 180/PI;
        dCurve = 2 * PI * R * (180 - alpha) / 360;
        dLength += dSide1 + dCurve;
    }

    if (N == 1) dLength = 2 * PI * R;
    if (N == 2) dLength = 2 * PI * R + 2 * dSide1;

    cout << setprecision(2) << setiosflags (ios::showpoint | ios::fixed) << dLength;
    return 0;
}