fork download
  1. /* package whatever; // don't place package name! */
  2. import java.util.Random;
  3. import java.util.*;
  4. import java.lang.*;
  5. import java.io.*;
  6.  
  7. /* Name of the class has to be "Main" only if the class is public. */
  8. class Ideone
  9. {
  10. public static double solution(int x1,int y1,int r1,int x2,int y2,int r2)
  11. {
  12. int intersect=0;
  13. int trials=200000*r1*r1*4;
  14. for(int i=0;i<trials;i++)
  15. {
  16. double x=(Math.random()-0.5) * r1*2+x1;
  17. double y=(Math.random()-0.5) * r1*2+y1;
  18. if( (x-x2)*(x-x2)+(y-y2)*(y-y2)<r2*r2 )intersect++;
  19. }
  20. return intersect*1.0/trials*(r1*r1)*3.1415926535;
  21. }
  22. public static void main (String[] args) throws java.lang.Exception
  23. {
  24. System.out.print(String.format("%.6f",solution(2,2,3,5,5,3)));
  25. // your code goes here
  26. }
  27. }
Success #stdin #stdout 0.49s 2841600KB
stdin
Standard input is empty
stdout
5.550413