zoukankan      html  css  js  c++  java
  • TZOJ 1210 The area(微积分)

    描述

    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 a random point on the parabola, and P2, P3 are the intersectant points. Any two points of P1, P2 and P3 are not coincidence each other.

    输入

    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).

    输出

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

    样例输入

    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

    样例输出

    33.33
    40.69

    提示

    For float may be not accurate enough, please use double instead of float.

    题意

    题意很简单,给你抛物线上三个点,p2和p3是线上的点,保证三点不共线,求上图红线画出的面积

    题解

    抛物线设y=ax^2+bx+c,把三个点代入公式,化简可得a,b,c

    直线设y=a1x+b1,a1为斜率,易得b1

    然后求积分∫(x2,x3)  ax2+bx+c-a1x-b1

    可得[1/3*ax3+1/2*bx2+cx-1/2*a1x2-b1x](x2,x3)  ==  [1/3*ax33+1/2*bx32+cx3-1/2*a1x32-b1x3]-[1/3*ax23+1/2*bx22+cx2-1/2*a1x22-b1x2] 即为答案

    代码

     1 #include<bits/stdc++.h>
     2 using namespace std;
     3 
     4 int main()
     5 {
     6     int T;
     7     scanf("%d",&T);
     8     while(T--)
     9     {
    10         double x1,y1,x2,y2,x3,y3,a1,b1,a,b,c,ans;
    11         scanf("%lf%lf%lf%lf%lf%lf",&x1,&y1,&x2,&y2,&x3,&y3);
    12         a1=(y3-y2)/(x3-x2);
    13         b1=y3-a1*x3;
    14         a=((y3-y1)-a1*(x3-x1))/((x3*x3-x1*x1)-(x3+x2)*(x3-x1));
    15         b=((y3-y2)-a*(x3*x3-x2*x2))/(x3-x2);
    16         c=y3-a*x3*x3-b*x3;
    17         ans=((1.0/3)*a*x3*x3*x3+0.5*(b-a1)*x3*x3+(c-b1)*x3)-((1.0/3)*a*x2*x2*x2+0.5*(b-a1)*x2*x2+(c-b1)*x2);
    18         printf("%.2f
    ",ans);
    19     }
    20     return 0;
    21 }
  • 相关阅读:
    E. Gosha is hunting (dp + wqs套wqs)
    【Codeforces Round #575 (Div. 3) 】 RGB Substring (hard version) ( FFT)
    C
    poj 1160 Post Office(dp + wqs二分)
    【 2018南京 】Magic Potion (网络流)
    【 2018南京 】Kangaroo Puzzle (思维+暴力模拟)
    【 2018南京 】Country Meow (模拟退火)
    【2018焦作网络赛】 Jiu Yuan Wants to Eat (熟练剖分 + 思维)
    【2018焦作网络赛】 Modular Production Line(费用流)
    【2018焦作网络赛】 B. Mathematical Curse (dp)
  • 原文地址:https://www.cnblogs.com/taozi1115402474/p/9465359.html
Copyright © 2011-2022 走看看