• hdoj 2036 (计算几何,叉积求面积)


    改革春风吹满地

    Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)
    Total Submission(s): 24179    Accepted Submission(s): 12504


    Problem Description
    “ 改革春风吹满地,
    不会AC没关系;
    实在不行回老家,
    还有一亩三分地。
    谢谢!(乐队奏乐)”

    话说部分学生心态极好,每天就知道游戏,这次考试如此简单的题目,也是云里雾里,而且,还竟然来这么几句打油诗。
    好呀,老师的责任就是帮你解决问题,既然想种田,那就分你一块。
    这块田位于浙江省温州市苍南县灵溪镇林家铺子村,多边形形状的一块地,原本是linle 的,现在就准备送给你了。不过,任何事情都没有那么简单,你必须首先告诉我这块地到底有多少面积,如果回答正确才能真正得到这块地。
    发愁了吧?就是要让你知道,种地也是需要AC知识的!以后还是好好练吧...
     
    Input
    输入数据包含多个测试实例,每个测试实例占一行,每行的开始是一个整数n(3<=n<=100),它表示多边形的边数(当然也是顶点数),然后是按照逆时针顺序给出的n个顶点的坐标(x1, y1, x2, y2... xn, yn),为了简化问题,这里的所有坐标都用整数表示。
    输入数据中所有的整数都在32位整数范围内,n=0表示数据的结束,不做处理。
     
    Output
    对于每个测试实例,请输出对应的多边形面积,结果精确到小数点后一位小数。
    每个实例的输出占一行。
     
    Sample Input
    3 0 0 1 0 0 1 4 1 0 0 1 -1 0 0 -1 0
     
    Sample Output
    0.5 2.0
     
    Author
    lcy
     
    Source
     
    一个多边形。
    n个定点按照逆时针方向给出..
    求面积。
     1 /*************************************************************************
     2     > File Name: code/hdoj/2036.cpp
     3     > Author: 111qqz
     4     > Email: rkz2013@126.com 
     5     > Created Time: 2015年11月06日 星期五 12时05分30秒
     6  ************************************************************************/
     7 
     8 #include<iostream>
     9 #include<iomanip>
    10 #include<cstdio>
    11 #include<algorithm>
    12 #include<cmath>
    13 #include<cstring>
    14 #include<string>
    15 #include<map>
    16 #include<set>
    17 #include<queue>
    18 #include<vector>
    19 #include<stack>
    20 #include<cctype>
    21 #define fst first              
    22 #define lson l,m,rt<<1
    23 #define rson m+1,r,rt<<1|1
    24 #define ms(a,x) memset(a,x,sizeof(a))
    25 using namespace std;
    26 const int dx4[4]={1,0,0,-1};
    27 const int dy4[4]={0,-1,1,0};
    28 typedef long long LL;
    29 #define sec second
    30 const int inf = 0x3f3f3f3f;
    31 const int N=105;
    32 int n;
    33 struct point 
    34 {
    35     double x,y;
    36     point(){}
    37     point(double _x,double _y):
    38     x(_x),y(-y){};
    39     void input()
    40     {
    41     scanf("%lf%lf",&x,&y);
    42     }
    43     double det(point p)
    44     {
    45     return x*p.y-y*p.x;
    46     }
    47 };
    48 struct  polygon
    49 {
    50     point  p[N];
    51     void input()
    52     {
    53     for ( int i = 0 ; i < n ; i++)
    54     {
    55         p[i].input();
    56     }
    57     }
    58     double getarea()
    59     {
    60     double sum= 0 ;
    61     int i;
    62     for ( int i = 0 ; i < n ; i++ )
    63     {
    64         sum+=p[i].det(p[(i+1)%n]);
    65     }
    66     return fabs(sum)/2;
    67     }
    68 }pol;
    69 int main()
    70 {
    71   #ifndef  ONLINE_JUDGE 
    72    freopen("in.txt","r",stdin);
    73   #endif
    74    while (scanf("%d",&n)!=EOF&&n)
    75     {
    76     pol.input();
    77     printf("%.1f
    ",pol.getarea());
    78     }
    79 
    80   
    81    
    82  #ifndef ONLINE_JUDGE  
    83   fclose(stdin);
    84   #endif
    85     return 0;
    86 }
    View Code
     
  • 相关阅读:
    利用反射获取类的所有字段
    System.Data.Entity.Internal.AppConfig 类型初始值设定项引发异常
    sql server 修改列类型
    sql server 删除表字段和字段的约束
    sql server 查找字段上的约束
    ASP.NET MVC自定义路由
    初探pandas——索引和查询数据
    初探pandas——安装和了解pandas数据结构
    初探numpy——numpy常用通用函数
    初探numpy——广播和数组操作函数
  • 原文地址:https://www.cnblogs.com/111qqz/p/4942357.html
Copyright © 2020-2023  润新知