• 博客园logo
  • 会员
  • 众包
  • 新闻
  • 博问
  • 闪存
  • 赞助商
  • HarmonyOS
  • Chat2DB
    • 搜索
      所有博客
    • 搜索
      当前博客
  • 写随笔 我的博客 短消息 简洁模式
    用户头像
    我的博客 我的园子 账号设置 会员中心 简洁模式 ... 退出登录
    注册 登录
dwtfukgv
博客园    首页    新随笔    联系   管理    订阅  订阅
HDU 2036 改革春风吹满地 (计算几何)

题意:你懂得。

析:没什么可说的,求面积用叉乘,尽量不要用海伦公式,因为计算量大,而且精度损失。

代码如下:

#include <iostream>
#include <cstdio>
#include <cstring>
#include <queue>
#include <set>
#include <vector>
#include <algorithm>

using namespace std;
const int maxn = 100 + 5;
int x[maxn], y[maxn];

int cross(int x1, int y1, int x2, int y2){
    return x1 * y2 - x2 * y1;
}

int main(){
    int n;
    while(scanf("%d", &n) == 1 && n){
        for(int i = 0; i < n; ++i)  scanf("%d %d", &x[i], &y[i]);

        x[n] = x[0];  y[n] = y[0];
        double s = 0.0;
        for(int i = 0; i < n; ++i)  s += cross(x[i], y[i], x[i+1], y[i+1]);
        printf("%.1lf\n", s/2.0);
    }
}

 

posted on 2016-07-01 21:32  dwtfukgv  阅读(240)  评论(0)    收藏  举报
刷新页面返回顶部
博客园  ©  2004-2025
浙公网安备 33010602011771号 浙ICP备2021040463号-3