fork download
  1. /****************************
  2. * Advitiya Brijesh *
  3. * Speedcuber :P *
  4. ****************************/
  5. // WA TLE MLE RE IDLE and counting...
  6. #include<bits/stdc++.h>
  7. using namespace std;
  8. // std macros
  9. typedef long long ll;
  10. typedef vector<list<ll> > vli;
  11. typedef vector<ll > vi;
  12. typedef vector<pair<ll,ll> > vpll;
  13. typedef vector<pair<int,int> > vpii;
  14. typedef pair<int ,int> pii;
  15. // dereference
  16. #define F first
  17. #define S second
  18. #define pb push_back
  19. #define mp make_pair
  20. #define in insert
  21. #define pu push
  22. #define fr front
  23. // loops
  24. #define rep(i,n) for(int i=0;i<n;++i)
  25. #define REP(i,a,b) for(int i=a;i<=b;++i)
  26. #define PER(i,b,a) for(int i=b;i>=a;--i)
  27. #define all(X) (X).begin(), (X).end()
  28. // I/O
  29. #define sd2(x,y) scanf("%d%d",&x,&y)
  30. #define sd3(x,y,z) scanf("%d%d%d",&x,&y,&z)
  31. #define sll2(x,y) scanf("%lld%lld",&x,&y)
  32. #define sll3(x,y,z) scanf("%lld%lld%lld",&x,&y,&z)
  33. #define sd(n) scanf("%d",&n)
  34. #define sll(n) scanf("%lld",&n)
  35. #define sc(n) scanf("%c",&n)
  36. #define ss(n) scanf("%s",n)
  37. #define oll(n) printf("%lld\n",n)
  38. // debug
  39. #define debug(x) cout<<"debug->"<<#x<<"::"<<x<<endl
  40. #define debug2(x,y) cout<<#x<<" :: "<<x<<"\t"<<#y<<" :: "<<y<<"\n"
  41. #define debug3(x,y,z) cout<<#x<<" :: "<<x<<"\t"<<#y<<" :: "<<y<<"\t"<<#z<<" :: "<<z<<"\n"
  42. // set values
  43. #define mset(n,k) memset(n,k,sizeof(n))
  44. #define MOD 1000000007
  45. ll INV2=500000004;
  46. ll INV6=166666668;
  47. //modular expo
  48. ll power(ll a,ll b, ll c){
  49. ll x=1,y=a;
  50. while(b>0){
  51. if(b&1)
  52. x=(x*y)%c;
  53. y=(y*y)%c;
  54. b/=2;
  55. }
  56. return x%c;
  57. }
  58. //perfect numbers till 10^6 6, 28, 496, 8128
  59. int dx[]={0,-1,0,1};
  60. int dy[]={-1,0,1,0};//clockwise from left
  61. long double doit(long double x,long double a0,long double a1,long double a2,long double a3,long double a4,long double a5,long double a6)
  62. {
  63. long double val=a0*a0*pow(x,13)/13.0 + pow(x,12)*(2*a0*a1)/12.0 + pow(x,11)*(2*a0*a2+a1*a1)/11.0 + pow(x,10)*(2*a0*a3+2*a1*a2)/10.0 + pow(x,9)*(2*a0*a4+2*a1*a3+a2*a2)/9.0 + pow(x,8)*(2*a0*a5+2*a1*a4+2*a2*a3)/8.0 + pow(x,7)*(2*a0*a6+2*a1*a5+2*a2*a4+a3*a3)/7.0 + pow(x,6)*(2*a1*a6+2*a2*a5+2*a3*a4)/6.0 + pow(x,5)*(2*a2*a6+2*a3*a5+a4*a4)/5.0 + pow(x,4)*(2*a3*a6+2*a4*a5)/4.0 + pow(x,3)*(2*a4*a6+a5*a5)/3.0 + pow(x,2)*(2*a5*a6)/2.0 + pow(x,1)*(a6*a6)/1.0;
  64. long double pi=acos(-1);
  65. return pi*val;
  66. }
  67. long double func(long double a,long double b,long double a0,long double a1,long double a2,long double a3,long double a4,long double a5,long double a6)
  68. {
  69. return doit(b,a0,a1,a2,a3,a4,a5,a6)-doit(a,a0,a1,a2,a3,a4,a5,a6);
  70. }
  71. long double f(long double x,long double a0,long double a1,long double a2,long double a3,long double a4,long double a5,long double a6)
  72. {
  73. return pow(x,6)*a0 + pow(x,5)*a1 + pow(x,4)*a2 + pow(x,3)*a3 + pow(x,2)*a4 + pow(x,1)*a5 + a6;
  74. }
  75. long double fder(long double x,long double a1,long double a2,long double a3,long double a4,long double a5,long double a6)
  76. {
  77. return 5*a1*pow(x,4)+4*a2*pow(x,3)+3*a3*pow(x,2)+2*a4*x+a5;
  78. }
  79. long double f2(long double x,long double a0,long double a1,long double a2,long double a3,long double a4,long double a5,long double a6)
  80. {
  81. return f(x,a0,a1,a2,a3,a4,a5,a6)*f(x,a0,a1,a2,a3,a4,a5,a6);
  82. }
  83. long double area(long double x,long double sl,long double a0,long double a1,long double a2,long double a3,long double a4,long double a5,long double a6)
  84. {
  85. long double theta=360/sl;
  86. long double val=f2(x,a0,a1,a2,a3,a4,a5,a6);
  87. theta=sin(theta)/2;
  88. return val*theta;
  89. }
  90. int main()
  91. {
  92.  
  93. int t;
  94. sd(t);
  95. REP(p,1,t)
  96. {
  97. long double n;
  98. scanf("%Lf",&n);
  99. long double a[10];
  100. rep(i,n+1)
  101. scanf("%Lf",&a[i]);
  102. long double a0,a1,a2,a3,a4,a5,a6;
  103. a0=a1=a2=a3=a4=a5=a6=0;
  104. if(n==1)
  105. a5=a[0],a6=a[1];
  106. if(n==2)
  107. a4=a[0],a5=a[1],a6=a[2];
  108. if(n==3)
  109. a3=a[0],a4=a[1],a5=a[2],a6=a[3];
  110. if(n==4)
  111. a2=a[0],a3=a[1],a4=a[2],a5=a[3],a6=a[4];
  112. if(n==5)
  113. a1=a[0],a2=a[1],a3=a[2],a4=a[3],a5=a[4],a6=a[5];
  114. long double aa,bb,slices,stacks;
  115.  
  116. scanf("%Lf%Lf%Lf%Lf",&aa,&bb,&slices,&stacks);
  117.  
  118. long double tr=func(aa,bb,a0,a1,a2,a3,a4,a5,a6);
  119.  
  120. long double ap=0,vv=(bb-aa)/stacks;
  121.  
  122. for(int i=0;i<stacks;++i)
  123. {
  124. long double as=aa+(i)*vv;
  125. long double bs=aa+(i+1)*vv;
  126. long double theta=360.0/slices;
  127. long double pi=acos(-1);
  128. theta=theta*pi/180;
  129. long double fas=f(as,a0,a1,a2,a3,a4,a5,a6),fbs=f(bs,a0,a1,a2,a3,a4,a5,a6);
  130. long double zero=as-((bs-as)/(fbs-fas))*fas;
  131. long double ar1=((bs-zero)*f2(bs,a0,a1,a2,a3,a4,a5,a6)*slices*sin(theta))/6.0;
  132. long double ar2=((as-zero)*f2(as,a0,a1,a2,a3,a4,a5,a6)*slices*sin(theta))/6.0;
  133. long double ar=ar1-ar2;
  134. ap+=ar;
  135. }
  136. long double ans=fabs(tr-ap);
  137. ans/=tr;
  138. ans*=100.0;
  139.  
  140. printf("Case %d: %.4Lf\n",p,ans);
  141. }
  142.  
  143.  
  144. return 0;
  145. }
Success #stdin #stdout 0s 3476KB
stdin
2
2 1 -4 5 1 4 4 3
1 1 0 1 4 4 3
stdout
Case 1: 27.9042
Case 2: 36.3380