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\n",sum);
} int main(){
while(scanf("%lf%d",&d,&n)!=EOF){
if(fabs(d-0.0)<eps && n==0) break;
input();
solve();
}
return 0;
}

uva 10406 Cutting tabletops的更多相关文章

  1. uva 10003 Cutting Sticks 【区间dp】

    题目:uva 10003 Cutting Sticks 题意:给出一根长度 l 的木棍,要截断从某些点,然后截断的花费是当前木棍的长度,求总的最小花费? 分析:典型的区间dp,事实上和石子归并是一样的 ...

  2. UVA 10003 Cutting Sticks 区间DP+记忆化搜索

    UVA 10003 Cutting Sticks+区间DP 纵有疾风起 题目大意 有一个长为L的木棍,木棍中间有n个切点.每次切割的费用为当前木棍的长度.求切割木棍的最小费用 输入输出 第一行是木棍的 ...

  3. UVa 10003 - Cutting Sticks(区间DP)

    链接: https://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&page=show_problem& ...

  4. UVA 10003 Cutting Sticks 切木棍 dp

    题意:把一根木棍按给定的n个点切下去,每次切的花费为切的那段木棍的长度,求最小花费. 这题出在dp入门这边,但是我看完题后有强烈的既是感,这不是以前做过的石子合并的题目变形吗? 题目其实就是把n+1根 ...

  5. UVA 10003 Cutting Sticks

    题意:在给出的n个结点处切断木棍,并且在切断木棍时木棍有多长就花费多长的代价,将所有结点切断,并且使代价最小. 思路:设DP[i][j]为,从i,j点切开的木材,完成切割需要的cost,显然对于所有D ...

  6. uva 10003 Cutting Sticks(区间DP)

    题目连接:10003 - Cutting Sticks 题目大意:给出一个长l的木棍, 再给出n个要求切割的点,每次切割的代价是当前木棍的长度, 现在要求输出最小代价. 解题思路:区间DP, 每次查找 ...

  7. UVA 10003 Cutting Sticks(区间dp)

    Description    Cutting Sticks  You have to cut a wood stick into pieces. The most affordable company ...

  8. UVA - 10003 Cutting Sticks(切木棍)(dp)

    题意:有一根长度为L(L<1000)的棍子,还有n(n < 50)个切割点的位置(按照从小到大排列).你的任务是在这些切割点的位置处把棍子切成n+1部分,使得总切割费用最小.每次切割的费用 ...

  9. uva 10003 Cutting Sticks (区间dp)

    本文出自   http://blog.csdn.net/shuangde800 题目链接:  打开 题目大意 一根长为l的木棍,上面有n个"切点",每个点的位置为c[i] 要按照一 ...

随机推荐

  1. Python api认证

    本节内容: 基本的api 升级的api 终极版api 环境:Djanao, 项目名:api_auto, app:api 角色:api端,客户端,黑客端 1.基本的api [api端] #api_aut ...

  2. ERP渠道活动管理(二十六)

    设计意义: 渠道活动的方式方法多种多样.不过,大至可分为销售型促销与市场型促销(一般来说,销售型促销以完成销售额为唯一目的,以奖励返点为唯一手段,以增大经销商库存为最终结果,短期行为明显.而市场型促销 ...

  3. 索引Hint提示(INDEX Hint)

    定义:所谓的索引Hint提示,就是强制查询优化器为一个查询语句执行扫描或者使用一个指定的索引 前提:利用索引提示的前提就是当前表存在索引了,如果是堆表的情况,只能通过表扫描获取数据了. 用处:很多时候 ...

  4. Scala 学习笔记(1)之入门篇

    Scala is pronounced skah-lah. Scala 全称为 scalable language,是一种面向对象(object)- 函数式(functional)静态类型(stati ...

  5. 【AtCoder】AtCoder Petrozavodsk Contest 001

    A - Two Integers 如果\(X\)是\(Y\)的倍数的话不存在 可以输出\(X \cdot (\frac{Y}{gcd(X,Y)} - 1)\) 代码 #include <bits ...

  6. 话说 SVN 与 Git 之间的区别

    如果你在读这篇文章,说明你跟大多数开发者一样对GIT感兴趣,如果你还没有机会来试一试GIT,我想现在你就要了解它了. GIT不仅仅是个版本控制系统,它也是个内容管理系统(CMS),工作管理系统等.如果 ...

  7. VS2010中设置程序以管理员身份运行

    VS2010中设置程序以管理员身份运行 直接项目右键---属性---连接器---清单文件---uac执行级别 选择requireAdministrator 重新编译 即可 这样程序直接运行就拥有管理员 ...

  8. 使用 jquery jroll2 开发仿qq聊天列表侧滑功能

    由于开发需求,需要做一个类似qq的聊天界面,侧滑弹出单条item右侧菜单,菜单可点击,效果如下图(包括点击事件+长按事件): 1.项目主体dom和css 页面结构比较简单,顶部header做了fixe ...

  9. 【转】SQL Server游标的使用

    在关系数据库中,我们对于查询的思考是面向集合的.而游标打破了这一规则,游标使得我们思考方式变为逐行进行.对于类C的开发人员来着,这样的思考方式会更加舒服. 正常面向集合的思维方式是: 而对于游标来说: ...

  10. RabbitMQ 延时消息队列

    消息延时在日常随处可见: 1.订单创建10min之后不发起支付,自动取消. 2.30min定时推送一次邮件信息. 最常用到方式后台定时任务轮训,量小的时候可以使用,量大会出现数据读取会性能问题.Rab ...