关闭

zoj1032 Area 2

1022人阅读 评论(0) 收藏 举报
  1. //zoj1032 Area 2
  2. //Accepted 1032 C++ 00:00.00 392K 
  3. #include <stdio.h>
  4. #define MAXN 100
  5.  
  6. struct point{ double x,y;};
  7.  
  8. double xmult(double x1,double y1,double x2,double y2){ return (x1*y2-y1*x2);}
  9. int gcd(int a,int b) { return b?gcd(b,a%b):a;}
  10. int abs(int x) { return x>0?x:(0-x);}
  11.  
  12. double area_polygon(int n, point *p)
  13. {
  14.        int i;
  15.        double ret=0;
  16.        for (i=0; i<n; ++i)
  17.               ret += xmult(p[i].x,p[i].y,p[i+1].x,p[i+1].y);
  18.        ret += xmult(p[n-1].x,p[n-1].y,p[0].x,p[0].y);
  19.        return ret/2;
  20. }
  21.  
  22. void solve()
  23. {
  24.        int i,n;
  25.        point p[MAXN+1];
  26.        int c,e;
  27.        double a;
  28.        int dx,dy;
  29.        scanf ("%d",&n);
  30.        p[0].x = p[0].y = 0;
  31.        e = 0;
  32.        for (i=0; i<n; ++i){
  33.               scanf ("%d %d",&dx,&dy);
  34.               e += gcd(abs(dx),abs(dy));
  35.               p[i+1].x = p[i].x+dx;
  36.               p[i+1].y = p[i].y+dy;
  37.        }
  38.        a = area_polygon(n+1,p);
  39.        c = (int)(a+1-0.5*(double)e);
  40.        printf ("%d %d %.1lf/n/n",c,e,a);
  41. }
  42.  
  43. int main()
  44. {
  45. #ifdef ONLINE_JUDGE
  46. #else
  47.        freopen("1032.txt","r",stdin);
  48. #endif
  49.        int i,t;
  50.        while (scanf ("%d",&t) != EOF)
  51.               for (i=1; i<=t; ++i){
  52.                      printf ("Scenario #%d:/n",i);
  53.                      solve();
  54.               }
  55. #ifdef ONLINE_JUDGE
  56. #else
  57.        fclose(stdin);
  58. #endif
  59.        return 0;
  60. }
0
0

查看评论
* 以上用户言论只代表其个人观点,不代表CSDN网站的观点或立场
    个人资料
    • 访问:36496次
    • 积分:664
    • 等级:
    • 排名:千里之外
    • 原创:33篇
    • 转载:0篇
    • 译文:0篇
    • 评论:10条
    文章分类
    最新评论