uva10060

   给定一堆多边形(凹凸都可能)薄板的坐标及厚度,和一个井盖的半径、厚度,求能覆盖掉多少井盖。 注意:多边形薄板可熔化,也即求出所有多边形的总体积,然后除以井盖的体积即可。

  理解了题意就好,很好做。另外,注意一下输入 。

#include <queue>
#include <stack>
#include <math.h>
#include <stdio.h>
#include <stdlib.h>
#include <iostream>
#include <limits.h>
#include <string.h>
#include <string>
#include <algorithm>
using namespace std;
const int MAX = 120000;
const double eps = 1e-6;
const double pi=3.141592654;
bool dy(double x,double y)	{	return x > y + eps;}	// x > y 
bool xy(double x,double y)	{	return x < y - eps;}	// x < y 
bool dyd(double x,double y)	{ 	return x > y - eps;}	// x >= y 
bool xyd(double x,double y)	{	return x < y + eps;} 	// x <= y 
bool dd(double x,double y) 	{	return fabs( x - y ) < eps;}  // x == y
struct point{	double x,y;		}a[MAX];
double crossProduct(point a,point b,point c)//向量 ac 在 ab 的方向 
{
	return (c.x - a.x)*(b.y - a.y) - (b.x - a.x)*(c.y - a.y);
}

double poly_are(point p[],int n)//多边形面积 
 {
        double ans=0.0;
        for(int i=1;i<n-1;i++)
        ans+=crossProduct(p[0],p[i],p[i+1]);
        return fabs(ans)/2.0;
 }

int main()
{
    int t,n;
    double thick,v,area,cthick,cr;
    while(cin>>t&&t)
    {
                    v=0.0;area=0.0;
                    while(t--)
                    {
                               cin>>thick;
                               n=0;
                               cin>>a[0].x>>a[0].y;
                               do{
                                   n++;
                                   scanf("%lf%lf",&a[n].x,&a[n].y); 
                                 }while(!(dd(a[n].x,a[0].x)&&dd(a[n].y,a[0].y)));
                                   //area+=poly_are(a,n);
                                   v+=poly_are(a,n)*thick;                  
                    } 
                    cin>>cr>>cthick;
                    double cv=pi*cr*cr*cthick;
                    int num=(int)(v/cv);
                    //int num=(int)v/cv; 忘加括号 ,结果出现了警告 ,但是结果正确, 。 But WA。改过之后 ,A了。可见 UVA卡的更严。 
                    cout<<num<<endl;
    }
return 0;
}




评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值