yijiull

题目链接:

用皮克定理:

一个计算点阵中顶点在格点上的多边形面积公式:S=a+b/2-1

其中a表示多边形内部的点数,b表示多边形边界上的点数,s表示多边形的面积。

 1 #include<cstdio>
 2 #include<cmath>
 3 #define ll long long
 4 using namespace std;
 5 struct point
 6 {
 7     double x,y;
 8 }p[1010];
 9 int gcd(int a, int b)
10 {
11     return b==0?a:gcd(b,a%b);
12 }
13 
14 double cross(point a,point b)
15 {
16     return a.x*b.y-a.y*b.x;
17 }
18 
19 
20 int main()
21 {
22     int n;
23     double ans=0,tmp=0;
24     while(scanf("%d",&n)&&n){
25             ans=0;
26             tmp=0;
27     for(int i=0;i<n;i++)
28         scanf("%lf%lf",&p[i].x,&p[i].y);
29 
30     for(int i=0;i<n;i++)
31     {
32         ans+=cross(p[i],p[(i+1)%n])/2.0;
33         tmp+=gcd(abs(p[i].x-p[(i+1)%n].x),abs(p[i].y-p[(i+1)%n].y) );  //边界上的点
34     }
35     ans=fabs(ans);
36     long long t= ans-tmp/2.0+1;   //要用long long  
37     printf("%lld\n",t);
38     }
39 }

 

分类:

技术点:

相关文章:

  • 2021-04-24
  • 2021-08-31
  • 2021-11-04
  • 2021-04-16
  • 2022-01-26
  • 2021-06-30
  • 2021-10-29
  • 2021-09-10
猜你喜欢
  • 2021-11-04
  • 2021-04-20
  • 2021-12-05
  • 2021-11-04
  • 2021-11-04
  • 2022-01-26
  • 2021-08-09
相关资源
相似解决方案