あとで
class PolygonRotation { public: double getVolume(vector <int> x, vector <int> y) { int N = x.size(); int mid; REP(i, N) if(x[i]==0) mid=i; vector<P> l, r, all; REP(i, N) { if(i<=mid) { r.PB(P{(double)x[i], (double)y[i]}); } if(i>=mid) { l.PB(P{(double)-x[i], (double)y[i]}); } } l.PB(P{(double)-x[0], (double)y[0]}); vector<double> ys(ALL(y)); REP(i, l.size()-1) REP(j, r.size()-1) { auto rv = intersection(l[i], l[i+1], r[j], r[j+1]); if(rv.first) { ys.PB(rv.second.y); } } sort(ALL(ys)); vector<double> xs(ys.size()); REP(i, ys.size()) { // find max x for ys[i] double y = ys[i]; for(auto& e : {l, r}) { REP(j, e.size()-1) { double ra = (y - e[j].y) / (e[j+1].y-e[j].y); if(0 <= ra && ra <= 1) { xs[i] = max(xs[i], e[j].x + ra * (e[j+1].x-e[j].x)); } } } } double ans = 0; REP(i, ys.size()-1) { double h = ys[i+1]-ys[i]; double r1 = xs[i]; double r2 = xs[i+1]; ans += M_PI*h/3.0*(r1*r1+r1*r2+r2*r2); } return ans; } };