zoukankan      html  css  js  c++  java
  • HDU 1071 The area 求定积分

    The area

    Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)
    Total Submission(s): 5074    Accepted Submission(s): 3542


    Problem 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
     
    /*
    题意:求定积分
    	知道三个点了 就可以求出直线和抛物线的方程 
    用抛物线的顶点公式y=a(x-x1)^2+y1外加另一个点x2算出a,再求出直线方程,之后求定积分
    */
    
    //代码一:———WA 不知道哪错了 就是交不上
    #include<stdio.h>
    double x1,x2,x3,y,y2,y3;  //不能定义y1,系统内部好像占用了,y1用y代替了。
    
    double fun(double x)
    {
    	return (y2-y)*(x-x1)*(x-x1)*(x-x1)/(3*(x2-x1)*(x2-x1))-(y3-y2)*x*x/(2*(x3-x2))+x*(y-y2+(y3-y2)/(x3-x2));
    }
    
    int main()
    {
    	int T;
    	scanf("%d",&T);
    	while(T--)
    	{
    		scanf("%lf%lf%lf%lf%lf%lf",&x1,&y,&x2,&y2,&x3,&y3);
    		printf("%.2lf%\n",fun(x3)-fun(x2));
    	}
    	return 0;
    }
    
    //不想浪费时间了 ,copy代码AC:
    
    #include<stdio.h>
    int main()
    {
        int n,i;
        double x0,y0,x1,y1,x2,y2,k,b,a,c,h,s;
        scanf("%d",&n);
        for(i=1;i<=n;i++)
        {
            scanf("%lf%lf%lf%lf%lf%lf",&x0,&y0,&x1,&y1,&x2,&y2);
            k=(y2-y1)/(x2-x1);
            b=y1-k*x1;
            h=x0;
            c=y0;
            a=(y1-c)/((x1-h)*(x1-h));
            s=(a*x2*x2*x2/3-(2*a*h+k)*x2*x2/2+(a*h*h+c-b)*x2)-(a*x1*x1*x1/3-(2*a*h+k)*x1*x1/2+(a*h*h+c-b)*x1);
            printf("%.2f\n",s);
        }
        return 0;
    }
    

      

    功不成,身已退
  • 相关阅读:
    算法之递归(4) 应用
    算法之递归(1)
    [Async] [Series #1] 初识Async异步编程模型。
    CVE202142287/CVE202142278 复现
    易读文库下载器1.2版发布
    Sqlite.net 读取DateTime异常的解决方案
    QZFL 2.0.5 源代码
    Sqlite 管理工具 SQLiteDeveloper 及破解
    visio2010数据库正向工程生成数据库脚本
    什么是高内聚、低耦合?
  • 原文地址:https://www.cnblogs.com/dongsheng/p/2684031.html
Copyright © 2011-2022 走看看