1179. Extrusion

Constraints

Time Limit: 1 secs, Memory Limit: 32 MB

Description

The Acme Extrusion Company specializes in the production of steel bars with custom-designed cross-sections. The manufacturing process involves cutting a hole in a thick metal plate, the shape of the hole being determined by the customer's specifications.

Molten metal is then forced through the hole to form a long bar. The shape of the hole determines the shape of the cross-section of the resulting bar.

Given a description of a polygonal hole and the volume of molten metal available, determine how long a bar can be formed by this process.


 

Input

Input consists of one or more data sets consisting of the following information:

  • An integer, N , indicating the number of vertices making up the polygon. End of input is signaled by any N less than 3.
  • Next are N lines, each containing a pair of floating-point numbers, (xiyi) , each denoting one vertex of the polygon. Vertices will be presented in clockwise order (relative to the closest interior point) proceeding around the perimeter of the polygon. The xi and yi values are in units of meters.
  • The data set is terminated by a floating point value indicating the amount of molten metal available (in cubic meters).

Output

For each data set, the program should produce a single line of output of the form: BAR LENGTH: x where ``x " is the maximum bar length, a floating point number expressed with two digits precision.

Sample Input

4 
0.0 0.0 
0.0 0.1 
0.1 0.1 
0.1 0.0 
1.0 
7 
0.5 1.25 
0.9 1.6 
0.9  1.1 
0.85 1.0 
0.9 0.85 
0.9 0.5 
0.5 0.75 
100.0 
0

Sample Output

BAR LENGTH: 100.00 
BAR LENGTH: 318.73
思路
主要是求多边形面积
|(x2*y1-y2*x1+x3*y2-y3*x2+…+x1*yn-y1*xn)|/2

#include<iostream>
#include<iomanip>
using namespace std;
int main()
{
  int mount;
    cin>>mount;
  while(mount>=3)
  {
   
    double a,b,area=0,x0,y0,x,y;
    cin>>a>>b;
    x0=a;
    y0=b;
    for (int i = 1; i < mount; ++i)
    {
      /* code */
         cin>>x>>y;
         area+= x*b-y*a;
      a=x;
      b=y;
    }
    area+=x0*b-y0*a;
    double cube;
    cin>>cube;
    cout<<"BAR LENGTH: "<<fixed<<setprecision(2)<<cube*2/area<<endl;
    cin>>mount;
  }
}


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值