zoukankan      html  css  js  c++  java
  • 1071解题报告

    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

    Hint

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

    设y=a*(x-b)^2+c
    y=ax^2-2abx+ab^2+c

    积分后1/3ax^3-abx^2+(ab^2+c)x

    jfp(double xu,double xd)计算抛物线与x轴之间的面积

    jfx(double xu,double xd)计算直线与x轴之间的面积

    然后将上下限带入相减就得到最后阴影面积。

    今天发现自己状态很不对,做了两小时都WA,经Chris检验,这个思路当然对。。但为什么答案不对?

    捣鼓了半天,想着把下面两点和x轴组成的面积用梯形公式求,但输出错误的结果跟用积分求相同,那就断定,求下面面积的公式正确。最后功夫不负有心人,chris发现了我竟然有把jfp写成如下形式

    double jfp(double xu,double xd){
        double ux = a*xu*xu*xu/3 - a*b*xu*xu + (a*b*b+c)*xu;
        double dx = a*xu*xu*xd/3 - a*b*xu*xd + (a*b*b+c)*xd;
        return ux-dx;
    }
    看出来了吧,复制粘贴罪大恶极,以后想不想再粘了!!!!????

    #include<iostream>
    #include<iomanip>
    #include<cmath>
    using namespace std;
    
    double a,b,c,k,b2;
    
    double jfp(double xu,double xd){
    	double ux = a*xu*xu*xu/3 - a*b*xu*xu + (a*b*b+c)*xu;
    	double dx = a*xd*xd*xd/3 - a*b*xd*xd + (a*b*b+c)*xd;
    	return ux-dx;
    }
    
    
    double jfx(double xu,double xd){
    	double ux = 0.5*k*xu*xu+b2*xu;
    	double dx = 0.5*k*xd*xd+b2*xd;
    	return ux-dx;
    }
    
    double y(double x){
    	return k*x + b2;
    }
    
    void main(){
    	int T;
    	cin>>T;
    	while(T>0){
    		double x1,x2,x3,y1,y2,y3;
    		cin>>x1>>y1>>x2>>y2>>x3>>y3;
    
    		a = (y2-y1)/((x2-x1)*(x2-x1));
    		b = x1;
    		c = y1;
    		k = (y3-y2)/(x3-x2);
    		b2 = y2-k*x2;//-(y(x2)+y(x3))*(x3-x2)/2.0;//
    		double area = jfp(x3,x2)-jfx(x3,x2);
    		cout.setf(ios::fixed);
    		cout.precision(2);
    		cout<<area<<endl;
    		T--;
    	}
    }
  • 相关阅读:
    8种Nosql数据库系统对比
    How to get the value of a form element : check box and radio button
    Jquery 操作Html 控件 CheckBox、Radio、Select 控件
    Reading CheckBoxes and Radio Buttons
    java中的匿名内部类总结
    如何理解java泛型类
    java 多态
    linux下使用 du查看某个文件或目录占用磁盘空间的大小
    内网ip范围
    Nginx配置优化参考
  • 原文地址:https://www.cnblogs.com/shenerguang/p/2322647.html
Copyright © 2011-2022 走看看