Pagini recente » Cod sursa (job #3262334) | Cod sursa (job #1245655) | Cod sursa (job #827458) | Cod sursa (job #1871098) | Cod sursa (job #933320)
Cod sursa(job #933320)
#include <fstream>
#include <iomanip>
using namespace std;
ifstream f("aria.in"); ofstream g("aria.out");
struct point{
long double x, y;
};
point v[100005];
long double surface;
int i, j, n;
/**
* | x1 y1 1 |
* det = | x2 y2 1 |
* | x3 y3 1 |
*
**/
inline long double det (long double x1, long double y1, long double x2, long double y2, long double x3, long double y3){
return x1*y2 + x2*y3 + x3*y1 - x1*y3 - x2*y1 - x3*y2;
}
int main(){
f>>n;
f>>v[1].x>>v[1].y;
for (i=2; i<=n; i++){
f>>v[i].x>>v[i].y;
surface += det(0, 0, v[i-1].x, v[i-1].y, v[i].x, v[i].y);
}
surface += det(0, 0, v[n].x, v[n].y, v[1].x, v[1].y);
if (surface < 0) surface *=-1;
// We did not divided the determinants by 2 in previous computations
surface /= 2.0;
g<<fixed<<setprecision(6);
g<<surface;
}