zoukankan      html  css  js  c++  java
  • HDU2036 改革春风吹满地

    第一次看到这题果断放弃,毕竟几何白痴,第二次刷没做的题的时候突然想到这个三角形面积的向量法:S=|x1*y2-x2*y1|  但是此题可能是凹多边形,所以不能加绝对值,可以画个凹四边形看看。

    
    
    HDU2036
    #include<cstdio>
    #include<cstdlib>
    #include<iostream>
    #include<memory.h>
    #include<algorithm>
    #include<cmath>
    using namespace std;
    int main()
    {
        int i,n;
        double x1,y1,x2,y2,x3,y3;
        double ans,temp;
        while(~scanf("%d",&n)){
            if(n==0) return 0;
            ans=0;
            cin>>x1>>y1>>x2>>y2;
            for(i=3;i<=n;i++){
                cin>>x3>>y3;
                temp=((x2-x1)*(y3-y1)-(x3-x1)*(y2-y1))*0.5;//思考为什么不要加绝对值 
                ans+=temp;
                x2=x3;y2=y3;
            }
            printf("%.1lf
    ",ans);
        }
        return 0;
    }
    
    
    
     
  • 相关阅读:
    CF Round 594
    [转载]CSP-J/S 第一轮知识点选讲
    10.17 模拟赛
    10.16 模拟赛
    10.15模拟赛
    10.14模拟赛
    10.12 模拟赛
    Peaks Gym 100365H
    手写Bitset优化
    Sums gym100753M
  • 原文地址:https://www.cnblogs.com/hua-dong/p/7603916.html
Copyright © 2011-2022 走看看