题解 UVA10060 【A hole to catch a man】

题目链接

Solution A hole to catch a man

题目大意:有\(n\)个多边形柱体,问将它们熔化后可以重铸成多少个给定规格的圆柱体


计算几何

分析:
显然我们只需要求出多边形柱体的体积记为\(sum\),圆柱的体积记为\(d\),那么答案就是\(\lfloor\frac{sum}{d}\rfloor\)

求多边形柱体体积在于求它的底面积,直接向量叉积算一下即可,由于题目貌似没有给定顺序(也可能是我没仔细看……),记得取绝对值

#include <iostream>
#include <vector>
#include <cmath>
using namespace std;
const double pi = acos(-1);
struct Point{
    double x,y;
    bool operator == (const Point &rhs)const{
        return x == rhs.x && y == rhs.y;
    }
}tmp;
typedef Point Vector;
inline double cross(Vector a,Vector b){return a.x * b.y - a.y * b.x;}
inline istream & operator >> (istream &in,Vector &x){
    in >> x.x >> x.y;
    return in;
}
vector<Vector> vec;
int n;
inline void solve(){
    vec.clear();
    double sum = 0;
    for(int i = 1;i <= n;i++){
        double h;cin >> h;
        Vector beg,last;
        cin >> beg;last = beg;
        double tmp = 0;
        while(true){
            Vector now;
            cin >> now;
            tmp += cross(last,now);
            if(now == beg)break;
            last = now;
        }
        sum += fabs(tmp) / 2.0 * h;
    }
    double r,t;
    cin >> r >> t;
    cout << (int)floor(sum / (pi * r * r * t)) << '\n';
}
int main(){
    while(cin >> n && n)solve();
    return 0;
}

另外谷歌翻译搞出来的极其有意思的题面……

猜你喜欢

转载自www.cnblogs.com/colazcy/p/12061650.html
man