zoukankan      html  css  js  c++  java
  • The area 积分积分

    The area
    Time Limit:1000MS     Memory Limit:32768KB     64bit IO Format:%I64d & %I64u
    Submit Status

    Description

    Ignatius bought a land last week, but he didn't know the area of the land because the land is enclosed by a parabola and a straight line. The picture below shows the area. Now given all the intersectant points shows in the picture, can you tell Ignatius the area of the land? 

    Note: The point P1 in the picture is the vertex of the parabola. 

     

    Input

    The input contains several test cases. The first line of the input is a single integer T which is the number of test cases. T test cases follow. 
    Each test case contains three intersectant points which shows in the picture, they are given in the order of P1, P2, P3. Each point is described by two floating-point numbers X and Y(0.0<=X,Y<=1000.0). 
     

    Output

    For each test case, you should output the area of the land, the result should be rounded to 2 decimal places. 
     

    Sample Input

    2
    5.000000 5.000000
    0.000000 0.000000
    10.000000 0.000000
    10.000000 10.000000
    1.000000 1.000000
    14.000000 8.222222
     

    Sample Output

    33.33
    40.69
     
     
     1 #include <iostream>
     2 #include <math.h>
     3 #include <stdio.h>
     4 #include <string.h>
     5 using namespace std;
     6 struct point
     7 {
     8     double x,y;
     9 } p1,p2,p3;
    10 double a,b,c,a1,b1;
    11 double F(double x)
    12 {
    13     return fabs(a*(x-b)*(x-b)+c-a1*x-b1);
    14 }
    15 void init()
    16 {
    17     b = p1.x;
    18     c = p1.y;
    19     a = (p2.y - c) / (p2.x - b) / (p2.x - b);
    20     a1 = (p3.y - p2.y) / (p3.x - p2.x);
    21     b1 = p2.y - a1 * p2.x;
    22     //cout<<a<<"   "<<b<<"    "<<c<<" "<<a1<<" "<<b1<<" "<<endl;
    23 }
    24 //三点辛普森公式
    25 double simpson(double width,double fa,double fb,double fc)
    26 {
    27     return (fb+fa+4*fc)*width/6;
    28 }
    29 
    30 //自适应simpson公式递归过程
    31 double asr(double a,double b,double eps,double A)
    32 {
    33     double c=(a+b)/2;
    34     double fa,fb,fc,L,R;
    35     fa=F(a);
    36     fb=F(b);
    37     fc=F(c);
    38     L=simpson(c-a,fa,fc,F((c+a)/2));
    39     R=simpson(b-c,fc,fb,F((b+c)/2));
    40     if(fabs(L+R-A)<=15*eps) return L+R+(L+R-A)/15;
    41     return asr(a,c,eps/2,L)+asr(c,b,eps/2,R);
    42 }
    43 double asr1(double a,double b,double eps)
    44 {
    45     return asr(a,b,eps,simpson(b-a,F(a),F(b),F((b+a)/2)));
    46 }
    47 int main()
    48 {
    49     int t;
    50     scanf("%d",&t);
    51     while(t--)
    52     {
    53         scanf("%lf%lf",&p1.x,&p1.y);
    54         scanf("%lf%lf",&p2.x,&p2.y);
    55         scanf("%lf%lf",&p3.x,&p3.y);
    56         init();
    57         printf("%.2lf
    ",asr1(p2.x,p3.x,0.0000001));
    58     }
    59 }
    View Code
     
     
  • 相关阅读:
    出现“尝试读取或写入受保护的内存。这通常指示其他内存已损坏”的解决方法
    angular中的:class的使用
    Vue中的:class的使用
    audio 音乐自动播放,循环播放,隐藏等
    vue放大缩小视图窗口按钮
    js获取显示器、页面等高度 (转)
    在 vue 中添加错误与成功提示的代码段
    在 vue 中添加初始化代码段
    学习react基本语法初始化webpack.pub.config.js
    学习react基本语法初始化webpack.config.js
  • 原文地址:https://www.cnblogs.com/ERKE/p/3889116.html
Copyright © 2011-2022 走看看