• hdu2036


    题解:

    求多边形面积

    分成很多块三角形求就可以了

    凹的也是支持的

    代码:

    #include <bits/stdc++.h>
    using namespace std;
    #define rint register int
    #define IL inline
    #define rep(i,h,t) for (int i=h;i<=t;i++)
    #define dep(i,t,h) for (int i=t;i>=h;i--)
    const double eps=1e-8;
    struct Point
    {
      double x,y;
      Point(double x1,double y1) {x=x1,y=y1;}
      Point(){};
      Point operator +(const Point b) const
      {
        return Point(x+b.x,y+b.y);
      }
      Point operator -(const Point b) const
      {
        return Point(x-b.x,y-b.y);
      }
      double operator *(const Point b) const
      {
        return x*b.x+y*b.y;
      }
      double operator ^(const Point b) const
      {
        return x*b.y-y*b.x;
      }
      Point operator *(double k)
      {
        return Point(x*k,y*k);
      }
      Point operator /(double k)
      {
        return Point(x/k,y/k);
      }
      bool operator ==(Point b)
      {
        return b.x==x&&b.y==y?1:0;
      } 
    };
    struct Line
    {
      Point x,y;
      Line() {};
      Line(Point x1,Point y1){x=x1,y=y1;};
    };
    double lenth(Point x)
    {
      return sqrt(x.x*x.x+x.y*x.y);
    }
    double angle(Point x,Point y)
    {
      return acos(x*y/lenth(x)/lenth(y));
    }
    int dcmp(double x)
    {
      if (x<-eps) return(-1);
      else if (x>eps) return(1);
      else return(0);
    }
    Point rotate(Point x,double r)
    {
      return Point(x.x*cos(r)-x.y*sin(r),x.x*sin(r)+x.y*cos(r));
    }
    Point gtp(Line x,Line y)
    {
      Point v1=x.y-x.x; Point v2=y.y-y.x;
      double k=((x.x^v1)-(y.x^v1))/(v2^v1);
      return y.x+v2*k;
    }
    double distance(Point x,Line y)
    {
      Point p1=x-y.x,p2=y.y-y.x;
      return fabs((p1^p2)/lenth(p2));
    }
    const int N=1000;
    Point p[N];
    int main()
    {
      freopen("1.in","r",stdin);
      freopen("1.out","w",stdout);
      ios::sync_with_stdio(false);
      int n;
      while (cin>>n&&n)
      {
        rep(i,1,n)
        {
          int x,y;
          cin>>x>>y;
          p[i]=Point(x,y);
        }
        double ans=0;
        rep(i,2,n-1)
          ans+=(p[i]-p[1])^(p[i+1]-p[1]);
        ans/=2;
        printf("%.1lf
    ",ans);
      }
      return 0;
    }
  • 相关阅读:
    Storyboard中segue使用总结
    Present ViewController Modally
    UILabel设置富文本格式显示
    objective-c 中随机数的用法 (3种:arc4random() 、random()、CCRANDOM_0_1() )
    ios中static的作用
    NSBundle的使用,注意mainBundle和Custom Bundle的区别
    OC的基础语法OC继承和复合语言特性目标动作回调
    动态规划-被3整除的子序列
    A
    Coins POJ
  • 原文地址:https://www.cnblogs.com/yinwuxiao/p/9992532.html
Copyright © 2020-2023  润新知