fork download
  1. #include <bits/stdc++.h>
  2. using namespace std;
  3. double minix,maxix;
  4. class circle
  5. {
  6. public:
  7. double x0,y0,r;
  8. pair<double,double> width;
  9. circle()
  10. {
  11. cin>>x0>>y0>>r;
  12. if(x0-r<minix)
  13. {
  14. minix=x0-r;
  15. }
  16. if(x0+r>maxix)
  17. {
  18. maxix=x0+r;
  19. }
  20. }
  21. pair<double,double> getwidth(double x)
  22. {
  23. width.first=y0;
  24. width.second=y0;
  25. if(x<=x0-r or x>=x0+r)
  26. {
  27. return width;
  28. }
  29. x=fabs((double)x-x0);
  30. double y = sqrt(r*r - x*x);
  31. width.first-=y;
  32. width.second+=y;
  33. return width;
  34. }
  35. };
  36.  
  37. int main() {
  38. int n,i,j;
  39. minix=2000;
  40. maxix=-2000;
  41. cin>>n;
  42. circle c[n];
  43. double x,ans=0;
  44. pair < double, double > currwidth;
  45. for(x=minix;x<maxix;x+=0.002)
  46. {
  47. double totalwidth=0;
  48. vector < pair<double,double> > widths;
  49. for(i=0;i<n;i++)
  50. {
  51. widths.push_back(c[i].getwidth(x));
  52. }
  53. sort(widths.begin(),widths.end());
  54. currwidth=widths[0];
  55. for(i=1;i<n;i++)
  56. {
  57. if(currwidth.second>=widths[i].second)
  58. {
  59. continue;
  60. }
  61. else if(currwidth.second<widths[i].first)
  62. {
  63. totalwidth+=currwidth.second - currwidth.first;
  64. currwidth=widths[i];
  65. }
  66. else
  67. {
  68. currwidth.second=widths[i].second;
  69. }
  70. }
  71. totalwidth+=currwidth.second - currwidth.first;
  72. ans+=totalwidth*0.002;
  73. }
  74. cout<<ans;
  75. return 0;
  76. }
  77.  
Success #stdin #stdout 0s 15240KB
stdin
3
0 0 1
0 0 1
100 100 1
stdout
6.28297