杭电2036题

来源:互联网 发布:大国重器 第二季 知乎 编辑:程序博客网 时间:2024/04/28 15:42
#include<iostream>
#include<iomanip>
#include<cmath>
using namespace std;
double area(int x1, int y1, int x2, int y2, int x3, int y3);
int main()
{
int a, b, c, d, e, f, n;
while (cin >> n&&n)
{
if (n<3 || n>100) break;
double s = 0.0;
cin >> a >> b >> c >> d >> e >> f;
s+=area(a, b, c, d, e, f);
n = n - 3;
while (n--)
{
c = e;
d = f;
cin >> e >> f;
s += area(a, b, c, d, e, f);
}
cout << fixed << setprecision(1) << abs(s) << endl;
}
return 0;

}
double area(int x1, int y1, int x2, int y2, int x3, int y3)
{
return(((x2 - x1)*(y3 - y1) -(y2 - y1)*(x3 - x1))*0.5);
}


尼玛啊!就这个代码写了一下午,总结起来就是自己没有真正的掌握  叉积,,导致abs 放置的位置有误。。
而杭电  测试的;例子又少,没有测试出错误,所以  。。。哎,自己还是粗心,,实力还是不高,。。努力吧!
0 0