标签:
题目链接:http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemId=5601
题意:求一个绕y轴旋转的旋转体体积。R = 2+cos(z)。
思路:旋转体体积可以直接用积分求出来,旋转体表面积公式对于此题积分比较难积,所以用矩形法来求积分。
1 #include <bits/stdc++.h> 2 using namespace std; 3 int T; 4 double z1, z2, V, area; 5 const double pai = acos(-1.0); 6 double getV() 7 { 8 double x1 = 4.5*z1 + 4*sin(z1) + 0.25*sin(2*z1); 9 double x2 = 4.5*z2 + 4*sin(z2) + 0.25*sin(2*z2); 10 return pai*(x2-x1); 11 } 12 double fun(double x) 13 { 14 return 2*pai*(2+cos(x))*sqrt(1.0+sin(x)*sin(x)); 15 } 16 double getpart(double x, double y) 17 { 18 double ans = 0; 19 double cut = (y-x)/5000; 20 double low = x, high; 21 for(int i = 1; i <= 5000; i++) 22 { 23 high = low+cut; 24 ans += (fun(low) + fun(high))/2*cut; 25 low += cut; 26 } 27 return ans; 28 } 29 int main() 30 { 31 scanf("%d", &T); 32 while(T--) 33 { 34 scanf("%lf%lf", &z1, &z2); 35 if(z1 > z2) swap(z1, z2); 36 37 V = getV(); 38 int cnt = int((z2-z1)/(pai*2)); 39 area = pai*(2+cos(z1))*(2+cos(z1)); 40 area += getpart(z1, z1+2*pai)*cnt; 41 area += getpart(z1+2*pai*cnt, z2); 42 printf("%.8lf %.8lf\n", V, area); 43 44 } 45 return 0; 46 }
标签:
原文地址:http://www.cnblogs.com/titicia/p/4816610.html