UVA Solution 358 - Don't Have A Cow - Solution in C, C++ | Volume 3 - Online Judge Solution

Latest

It is a free Online judges problems solution list. Here you can find UVA online Judge Solution, URI Online Judge Solution, Code Marshal Online Judge Solution, Spoz Online Judge Problems Solution

Friday, May 5, 2017

UVA Solution 358 - Don't Have A Cow - Solution in C, C++ | Volume 3

UVA Solution 358 - Don't Have A Cow - Solution in C, C++ | Volume 3


UVA Online Judge Solution 358 - Don't Have A Cow| Volume 3
UVA Problem Link - https://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&category=5&page=show_problem&problem=294

Problem Name: 358 - Don't Have A Cow
Problem Number : UVA - 358 - Don't Have A Cow
Online Judge : UVA Online Judge Solution
Volume: 3
Solution Language : C, C plus plus

UVA Solution 358 - Don't Have A Cow - Solution in C, C++ | Volume 3

UVA Solution 358 - Don't Have A Cow Code in C, CPP:


#include <stdio.h>
#include <math.h>
#include <iostream>
using namespace std;

#define eps 1e-8
int main() {
    int testcase;
    double R, P;
    const double pi = acos(-1);
    scanf("%d", &testcase);
    while (testcase--) {
        scanf("%lf %lf", &R, &P);
        double l = 0, r = pi, mid, ret = 0;
        double A = R * R * pi;
        while (fabs(l - r) > eps) {
            mid = (l + r)/2;
            ret = hypot(R * cos(mid) - R, R * sin(mid));
            double theta = (pi - mid)/2;
            double area = (ret * ret * theta/2 + (R * R * mid/2 - R * R * sin(mid)/2))*2;
            if (area < A * P)
                l = mid;
            else
                r = mid;
        }
        printf("R = %.0lf, P = %.2lf, Rope = %.2lf\n", R, P, ret);
        if(testcase)
            puts("");
    }
    return 0;
}
/*

*/

No comments:

Post a Comment