[???]多边形面积

[题目]  (见《中学高级本》)
[报告]
    这道题其实很简单,题目中给的条件太特殊了,其实网上面就有一般性的计算几何的方法,具体不介绍了,就是S=SUM{x[i-1]*y[i]-x[i]*y[i-1]}/2  i=1,2,3,...n,其中x[0]=x[n],y[0]=y[n],具体可以用叉积证明,在这里就不证明了,网上面遍地都是……
    至此,该题目已经完美解决……
[程序]
// TASK: area
#include <cstdlib>
#include <iostream>
#include <cstring>
#include <cstdio>
#include <fstream>
#define nil NULL
#define N 100
using namespace std;
ifstream fin ("area.in");
ofstream fout ("area.out");
long ans;
long n;
long x[N+1],y[N+1];
static inline void init()
{
    fin >> n;
    for (long i=1;i<=n;i++)
        fin >> x[i] >> y[i];
}
static inline void calc()
{
    ans=0;
    x[0]=x[n];y[0]=y[n];
    for (long i=1;i<=n;i++)
        ans+=x[i-1]*y[i]-x[i]*y[i-1];
}
static inline void ouot()
{
    fout << ans/2 << endl;
}
int main(int argc, char *argv[])
{
    init();
    calc();
    ouot();
    return EXIT_SUCCESS;
}

posted @ 2010-11-07 17:18  为美好世界献上珂学  阅读(120)  评论(0)    收藏  举报