• 1502: [NOI2005]月下柠檬树


    Description


    Input

    文件的第1行包含一个整数n和一个实数alpha,表示柠檬树的层数和月亮的光线与地面夹角(单位为弧度)。第2行包含n+1个实数h0,h1,h2,…,hn,表示树离地的高度和每层的高度。第3行包含n个实数r1,r2,…,rn,表示柠檬树每层下底面的圆的半径。上述输入文件中的数据,同一行相邻的两个数之间用一个空格分隔。输入的所有实数的小数点后可能包含1至10位有效数字。
    Output

    输出1个实数,表示树影的面积。四舍五入保留两位小数。
    Sample Input
    2 0.7853981633
    10.0 10.00 10.00
    4.00 5.00
    Sample Output
    171.97
    HINT

    1≤n≤500,0.3

    存个simpson模板

     1 uses math;
     2 const
     3     maxn=510;
     4     eps=1e-7;
     5 var
     6     x,rr,fx1,fy1,fx2,fy2,k:array[0..maxn]of double;
     7     n:longint;
     8     a,l,r,m,fl,fr,fm:double;
     9  
    10 function simpson(l,r,fl,fr,fm:double):double;
    11 begin
    12     exit((r-l)/6*(fl+fr+4*fm));
    13 end;
    14  
    15 function f(a:double):double;
    16 var
    17     i:longint;
    18 begin
    19     f:=0;
    20     for i:=1 to n do
    21         begin
    22             if abs(a-x[i])<rr[i] then f:=max(f,sqrt(sqr(rr[i])-sqr(a-x[i])));
    23             if (a>fx1[i]) and (a<fx2[i]) then f:=max(f,fy1[i]+(a-fx1[i])*k[i]);
    24         end;
    25 end;
    26  
    27 function area(l,m,r,fl,fm,fr,pre:double):double;
    28 var
    29     ll,rr,fll,frr,ls,rs:double;
    30 begin
    31     ll:=(l+m)/2;rr:=(m+r)/2;fll:=f(ll);frr:=f(rr);
    32     ls:=simpson(l,m,fl,fm,fll);rs:=simpson(m,r,fm,fr,frr);
    33     if abs(ls+rs-pre)<eps then exit(pre);
    34     exit(area(l,ll,m,fl,fll,fm,ls)+area(m,rr,r,fm,frr,fr,rs));
    35 end;
    36  
    37 procedure main;
    38 var
    39     i:longint;
    40 begin
    41     read(n,a);a:=1/tan(a);
    42     for i:=1 to n+1 do read(x[i]);
    43     for i:=2 to n+1 do x[i]:=x[i]+x[i-1];
    44     for i:=1 to n+1 do x[i]:=x[i]*a;
    45     for i:=1 to n do read(rr[i]);
    46     r:=x[n+1];l:=x[n+1];
    47     for i:=1 to n do
    48         begin
    49             if x[i]-rr[i]<l then l:=x[i]-rr[i];
    50             if x[i]+rr[i]>r then r:=x[i]+rr[i];
    51         end;
    52     for i:=1 to n do
    53         if (x[i]-rr[i]<x[i+1]-rr[i+1]) and (x[i]+rr[i]<x[i+1]+rr[i+1]) then
    54         begin
    55             fx1[i]:=x[i]+rr[i]*(rr[i]-rr[i+1])/(x[i+1]-x[i]);fy1[i]:=sqrt(sqr(rr[i])-sqr(fx1[i]-x[i]));
    56             fx2[i]:=x[i+1]+rr[i+1]*(rr[i]-rr[i+1])/(x[i+1]-x[i]);fy2[i]:=sqrt(sqr(rr[i+1])-sqr(fx2[i]-x[i+1]));
    57             if abs(fx2[i]-fx1[i])>eps then k[i]:=(fy2[i]-fy1[i])/(fx2[i]-fx1[i]);
    58         end;
    59     m:=(l+r)/2;fl:=f(l);fr:=f(r);fm:=f(m);
    60     writeln(2*area(l,m,r,fl,fm,fr,simpson(l,r,fl,fr,fm)):0:2);
    61 end;
    62  
    63 begin
    64     main;
    65 end.
    View Code
  • 相关阅读:
    C# 模式&模式匹配
    CentOS7下安装 dotnet sdk
    PLSQL 设置
    Visual Studio Code 开发 .NetCore 插件列表
    .net core 服务生命周期
    从 Asp.Net Core 2.2 迁移到 3.0 的方案
    CSRedisCore 介绍
    Entity Framework 命令
    DataAnnotations 模型配置
    依赖注入学习(理论)
  • 原文地址:https://www.cnblogs.com/Randolph87/p/3800664.html
Copyright © 2020-2023  润新知