美文网首页
【HDUoj 1071】The area

【HDUoj 1071】The area

作者: Siding | 来源:发表于2018-10-04 16:36 被阅读0次

The area(题目链接)

思路

  • 利用数学知识计算出面积
  • 加0.5实现四舍五入

代码

#include <iostream>
#include <string.h> 
using namespace std;
#define LOCAL 0

//three points 
double x1,x2,x3,y1,y2,y3;   
//the coefficients of the two functions
double a,b,c,k,t;           
double s;   //area

int main(){   
#if LOCAL
    freopen ("datain.txt","r",stdin);
    freopen ("dataout.txt","w",stdout);
#endif

    int n;
    cin >> n;
    for(int i = 0; i < n; i++){
        cin >> x1 >> y1;
        cin >> x2 >> y2;
        cin >> x3 >> y3;
        
        a = (((y2-y1) / (x2-x1)) - ((y3-y2) / (x3-x2))) / (x1-x3);
        b = ((y2-y1) / (x2-x1)) - (a * (x1+x2));
        c = y3 - (a * x3 * x3 + b * x3);
        k = (y3 - y2) / (x3 - x2);
        t = y2 - k * x2;
        s = ((a / 3)*x3*x3*x3 + ((b-k)/2)*x3*x3 + (c-t)*x3)
                - ((a / 3)*x2*x2*x2 + ((b-k)/2)*x2*x2 + (c-t)*x2);
        //round-off 
        int m = s * 100 + 0.5;
        s = m / 100.0;
        printf("%0.2f\n",s);
    }
    
    return 0;
}

相关文章

  • 【HDUoj 1071】The area

    The area(题目链接) 思路 利用数学知识计算出面积 加0.5实现四舍五入 代码

  • 简明刷题指南

    1. 刷题网站 HDUOJ Welcome To PKU JudgeOnline PAT Codeforces A...

  • xpath之extract()

    area_href = area.xpath("//map[@name='cnMap']/area/text()"...

  • hduoj water~~~1070

    Problem DescriptionIgnatius drinks milk everyday, now he ...

  • 1071

    8月31日,农历八月初五,周三,雨 八年前的今天,2014年8月31日中午,娃爷爷走了。到今天整八年。那天丫头去学...

  • 2019-02-27

    inhabit inhabit the area the area are inhabited by people...

  • Safe Area解析

    Safe Area解析(一) —— Safe Area由来及简单使用(一)Safe Area解析(二) —— 你为...

  • with复合结构

    region / area area 区域,没有界限desert area 沙漠地区 region 地区,通常有明...

  • 无限级分类,子孙树的递归与迭代

    ``` $area = array( array('id'=>1,'area'=>'北京','pid'=>0), ...

  • Gallery Basic3 Area

    Basic Area Multiare overlap Stacked Area Chart Stack with...

网友评论

      本文标题:【HDUoj 1071】The area

      本文链接:https://www.haomeiwen.com/subject/bjbxaftx.html