zoukankan      html  css  js  c++  java
  • [CF379E](New Year Tree Decorations)

    • 题意

    给你一堆坐标轴上的多边形,它们互相覆盖,求每个多边形露出部分的面积

    • solution

    正解(计算几何)是不可能会的

    有一种神奇的方法

    用类似于定积分的思想去做

    把每条边划分成很小很小的段,

    对于每段用矩形去近似覆盖

    即每段面积计算为左边线段长度乘以宽度

    玄学

    • code

    #include<iostream>
    #include<cstdio>
    #include<cstring>
    #include<algorithm>
    using namespace std;
    const int M=2000000;
    int n,k,m;
    long double height,h1,h2,ans,plk;
    long double front[M+1];
    int main(){
       scanf("%d%d",&n,&k);
       m=M/k;
       for(int i=1;i<=n;i++){
         ans=0.0;
         scanf("%Lf",&h1);
         for(int r=1;r<=k;r++){
            scanf("%Lf",&h2);//h1~h2代表一条线段
            plk=(h2-h1)/m;// plk 即斜率
            for(int p=0;p<m;p++){
               height=h1+plk*p; //当前点的y值
               if(height>front[(r-1)*m+p]){//front 即当前x坐标对应的最高节点,如果当前节点比它还高那么这段面积就是露在外面的,统计答案并更新front
                 ans+=height-front[(r-1)*m+p]; //面积公式(由于宽度等于1,就不乘宽度了)
                 front[(r-1)*m+p]=height;
                 }
               }
             h1=h2;
             }
       cout<<ans/m;
       putchar('
    ');
       }
    }
    
  • 相关阅读:
    A1143. Lowest Common Ancestor
    三个loading小动画实例
    CSS之圣杯布局与双飞翼布局
    sublime个人快捷键
    响应式之表格
    CSS之column语法
    使用column简单实现瀑布流效果
    Flex 布局教程:实例篇(转)
    Flex 布局教程:语法篇(转)
    简单实现瀑布流效果
  • 原文地址:https://www.cnblogs.com/stepsys/p/10383829.html
Copyright © 2011-2022 走看看