hdu1724定积分

其实是很简单的题,用定积分得到公式就行了,不过大学都毕业了我居然还会求定积分,忍不住想自夸一下^_^。。。

/*
 * hdu1724/win.cpp
 * Created on: 2012-7-6
 * Author    : ben
 */
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <ctime>
#include <iostream>
#include <algorithm>
#include <queue>
#include <set>
#include <map>
#include <stack>
#include <string>
#include <vector>
#include <deque>
#include <list>
#include <functional>
#include <numeric>
#include <cctype>
using namespace std;

double getarea(int a, int b, int L, int R) {
    double p1 = asin(R * 1.0 / a) * a * b;
    double p2 = asin(L * 1.0 / a) * a * b;
    double p3 = sqrt(a * a - R * R) * b * R / a;
    double p4 = sqrt(a * a - L * L) * b * L / a;
    return p1 - p2 + p3 - p4;
}

int main() {
#ifndef ONLINE_JUDGE
    freopen("data.in", "r", stdin);
#endif
    int T, a, b, L, R;
    scanf("%d", &T);
    while(T--) {
        double ans;
        scanf("%d%d%d%d", &a, &b, &L, &R);
        if(L >= 0) {
            ans = getarea(a, b, L, R);
        }else {
            ans = getarea(a, b, 0, R);
            ans += getarea(a, b, 0, -L);
        }
        printf("%.3f\n", ans);
    }
    return 0;
}

 

posted @ 2012-07-06 16:13  moonbay  阅读(146)  评论(0编辑  收藏  举报