zoukankan      html  css  js  c++  java
  • POJ3907 Build Your Home

    嘟嘟嘟

    题意:按逆时针或顺时针给出一个多边形,求面积。

    解法:直接套用公式:(S = frac{1}{2}|sum _ {i = 1} ^ {n} {v_i imes v_{i + 1}}|)


    别忘了POJ实数输出的时候必须%(f),不能%(lf)……

    #include<cstdio>
    #include<iostream>
    #include<cmath>
    #include<algorithm>
    #include<cstring>
    #include<cstdlib>
    #include<cctype>
    #include<vector>
    #include<stack>
    #include<queue>
    using namespace std;
    #define enter puts("") 
    #define space putchar(' ')
    #define Mem(a, x) memset(a, x, sizeof(a))
    #define rg register
    typedef long long ll;
    typedef double db;
    const int INF = 0x3f3f3f3f;
    const db eps = 1e-8;
    const int maxn = 1e3 + 5;
    inline ll read()
    {
      ll ans = 0;
      char ch = getchar(), last = ' ';
      while(!isdigit(ch)) last = ch, ch = getchar();
      while(isdigit(ch)) ans = (ans << 1) + (ans << 3) + ch - '0', ch = getchar();
      if(last == '-') ans = -ans;
      return ans;
    }
    inline void write(ll x)
    {
      if(x < 0) x = -x, putchar('-');
      if(x >= 10) write(x / 10);
      putchar(x % 10 + '0');
    }
    
    int n;
    struct Vec
    {
      db x, y;
      db operator * (const Vec& oth)const
      {
        return x * oth.y - oth.x * y;
      }
    }a[maxn];
    
    db area()
    {
      a[n + 1] = a[1];
      db ans = 0;
      for(int i = 1; i <= n; ++i) ans += a[i] * a[i + 1];
      ans = ans < -eps ? -ans : ans;
      return ans / 2.00;
    }
    
    int main()
    {
      while(scanf("%d", &n) && n)
        { 
          for(int i = 1; i <= n; ++i) scanf("%lf%lf", &a[i].x, &a[i].y);
          printf("%.0f
    ", area());
        }
      return 0;
    }
    
  • 相关阅读:
    第一次冲刺04
    第一次冲刺03
    第一次冲刺02
    团队站立会议3(第二阶段)
    团队站立会议2(第二阶段)
    团队站立会议1(第二阶段)
    Alpha版总结会议
    “来用”alpha版使用说明书
    团队绩效评估计划
    第一阶段其他团队对我们的意见汇总
  • 原文地址:https://www.cnblogs.com/mrclr/p/9973831.html
Copyright © 2011-2022 走看看