【HDUoj 1071】The area

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;
}
©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容

  • Lua 5.1 参考手册 by Roberto Ierusalimschy, Luiz Henrique de F...
    苏黎九歌阅读 14,737评论 0 38
  • Android 自定义View的各种姿势1 Activity的显示之ViewRootImpl详解 Activity...
    passiontim阅读 175,335评论 25 709
  • 用两张图告诉你,为什么你的 App 会卡顿? - Android - 掘金 Cover 有什么料? 从这篇文章中你...
    hw1212阅读 14,472评论 2 59
  • 8月24日,乐清“滴滴顺风车司机杀人案”发生后,社会各界高度关注。 滴滴事件引发了我的一些思考: 1、如果公司员工...
    lily123321阅读 2,532评论 0 0
  • 海图 色彩画开端图, 万事开头难 但坚持比开头还重要 临摹莫奈作品
    春城怡景阅读 1,423评论 2 3