• HDU


    原题链接

    题意:

    给定 $a,b,l,r,$求 与$x = l,x = r$ 围成的封闭图形的面积。

    思路:

    大佬可以直接算一下原函数就出来了,当没法计算或者很难计算的时候就可以用 自适应$simpson$ 积分来逼近真实值。

     1 /*
     2 * @Author: windystreet
     3 * @Date:   2018-08-04 16:24:01
     4 * @Last Modified by:   windystreet
     5 * @Last Modified time: 2018-08-04 16:24:33
     6 */
     7 
     8 #include<bits/stdc++.h>
     9 
    10 using namespace std;
    11 
    12 #define X first
    13 #define Y second
    14 #define eps  1e-10                        // 精度根据题目改变
    15 #define gcd __gcd
    16 #define pb push_back
    17 #define PI acos(-1.0)
    18 #define lowbit(x) (x)&(-x)
    19 #define bug printf("!!!!!
    ");
    20 #define mem(x,y) memset(x,y,sizeof(x))
    21 
    22 typedef long long LL;
    23 typedef long double LD;
    24 typedef pair<int,int> pii;
    25 typedef unsigned long long uLL;
    26 
    27 const int maxn = 1e5+2;
    28 const int INF  = 1<<30;
    29 const int mod  = 1e9+7;
    30 
    31 double a,b;
    32 
    33 double f(double x){
    34     return b*(sqrt(1.0-(x*x)/(a*a)));    // 函数根据题目改变
    35 }
    36 double simpson(double L ,double R){
    37     return (R-L)*(f(L)+4.0*f((L+R)/2.0)+f(R))/6.0;
    38 }
    39 double asr(double L,double R){
    40     double mid = (L+R)/2.0;
    41     double res = simpson(L,R);
    42     double left = simpson(L,mid),right = simpson(mid,R);
    43     if(fabs(left+right-res)<eps)return left + right;
    44     else return asr(L,mid)+asr(mid,R);
    45 }
    46 
    47 
    48 void solve(){
    49     double l,r;
    50     scanf("%lf%lf%lf%lf",&a,&b,&l,&r);
    51     double ans = asr(l,r);
    52     printf("%.3lf
    ",2.0*ans);
    53     
    54     return;
    55 }
    56 
    57 int main()
    58 {
    59 //    freopen("in.txt","r",stdin);
    60 //    freopen("out.txt","w",stdout);
    61 //    ios::sync_with_stdio(false);
    62     int t = 1;
    63     scanf("%d",&t);
    64     while(t--){
    65     //    printf("Case %d: ",cas++);
    66         solve();
    67     }
    68     return 0;
    69 }
  • 相关阅读:
    SpringMVC
    MyBatis 与 Spring 的完美整合方法
    持久层之 MyBatis: 第三篇 :缓存 And 高级查询
    持久层之 MyBatis: 第二篇 :动态SQL And多表查询
    C语言实现简单epoll服务器(二)
    C语言简单实现epoll服务器(一)
    shell编程题(十九)
    shell编程题(十七)
    shell编程题(十六)
    shell编程题(十三)
  • 原文地址:https://www.cnblogs.com/windystreet/p/9419335.html
Copyright © 2020-2023  润新知