zoukankan      html  css  js  c++  java
  • uva 10406 Cutting tabletops

    Problem D: Cutting tabletops

    Bever Lumber hires beavers to cut wood. The company has recently received a shippment of tabletops. Each tabletop is a convex polygon. However, in this hard economic times of cutting costs the company has ordered the tabletops from a not very respectable but cheap supplier. Some of the tabletops have the right shape but they are slightly too big. The beavers have to chomp of a strip of wood of a fixed width from each edge of the tabletop such that they get a tabletop of a similar shape but smaller. Your task is to find the area of the tabletop after beavers are done.

    Input consists of a number of cases each presented on a separate line. Each line consists of a sequence of numbers. The first number is d the width of the strip of wood to be cut off of each edge of the tabletop in centimeters. The next number n is an integer giving the number of vertices of the polygon. The next npairs of numbers present xi and yi coordinates of polygon vertices for 1 <= i <= n given in clockwise order. A line containing only two zeroes terminate the input.

    d is much smaller than any of the sides of the polygon. The beavers cut the edges one after another and after each cut the number of vertices of the tabletop is the same.

    For each line of input produce one line of output containing one number to three decimal digits in the fraction giving the area of the tabletop after cutting.

    Sample input

    2 4 0 0 0 5 5 5 5 0
    1 3 0 0 0 5 5 0
    1 3 0 0 3 5.1961524 6 0
    3 4 0 -10 -10 0 0 10 10 0
    0 0
    

    Output for sample input

    1.000
    1.257
    2.785
    66.294
    

    Problem Setter: Piotr Rudnicki


    题目大意:

    顺时针给定你一个凸多边形。问你削去d距离后,这个凸多边形的面积


    解题思路:


    也就是原来的凸包面积减去全部以凸包边为长度高为d的矩形面积加上多去除的部分(也就是1,2,3,4,5的面积),就是答案


    解题代码:

    #include <iostream>
    #include <cstdio>
    #include <vector>
    #include <cmath>
    #include <algorithm>
    using namespace std;
    
    struct point{
        double x,y;
        point(double x0=0,double y0=0){x=x0;y=y0;}
        double xchen(point p){//this X P
            return x*p.y-p.x*y;
        }
        double dchen(point p){//this X P
            return x*p.x+y*p.y;
        }
        double getlen(){
            return sqrt ( x*x+y*y );
        }
        double getdis(point p){
            return sqrt( (x-p.x)*(x-p.x) + (y-p.y)*(y-p.y) );
        }
    };
    
    const double eps=1e-7;
    double d;
    int n;
    vector <point> p;
    
    void input(){
        p.resize(n);
        for(int i=0;i<n;i++){
            scanf("%lf%lf",&p[i].x,&p[i].y);
        }
    }
    
    void solve(){
        double sum=0;
        for(int i=1;i<n-1;i++){
            point p1=point(p[i].x-p[0].x,p[i].y-p[0].y);
            point p2=point(p[i+1].x-p[0].x,p[i+1].y-p[0].y);
            sum+=fabs(p2.xchen(p1))/2.0;
        }
        for(int i=0;i<n;i++){
            double dis=p[i].getdis(p[(i+n-1)%n]);
            sum-=dis*d;
        }
        for(int i=0;i<n;i++){
            int t1=((i-1)+n)%n,t2=((i+1)+n)%n;
            point p1=point(p[t1].x-p[i].x,p[t1].y-p[i].y);
            point p2=point(p[t2].x-p[i].x,p[t2].y-p[i].y);
            double degree=acos( p1.dchen(p2)/p1.getlen()/p2.getlen() ) /2.0;
            double area=d/(tan(degree) )*d;
            sum+=area;
        }
        printf("%.3lf
    ",sum);
    }
    
    int main(){
        while(scanf("%lf%d",&d,&n)!=EOF){
            if(fabs(d-0.0)<eps && n==0) break;
            input();
            solve();
        }
        return 0;
    }
    





  • 相关阅读:
    我的博客
    【git】给文件重命名的简便方法
    【git】通过几次commit来认识工作区和暂存区
    2018年2月份面试题
    【git】建git仓库
    【git】git的安装和最小配置
    selenium WebDriver的实现原理
    什么是selenium
    selenium的安装
    monkey停不下来了怎么整
  • 原文地址:https://www.cnblogs.com/lcchuguo/p/5393919.html
Copyright © 2011-2022 走看看