fork download
  1. import java.util.concurrent.ForkJoinPool;
  2. import java.util.concurrent.RecursiveAction;
  3. import java.util.concurrent.atomic.AtomicLong;
  4.  
  5.  
  6. public class Main {
  7.  
  8. public static void main(String[] args) {
  9. AtomicLong same = new AtomicLong();
  10. AtomicLong diff = new AtomicLong();
  11.  
  12. ForkJoinPool pool = new ForkJoinPool();
  13. pool.invoke(new Count(0, 0x100000000l, same, diff));
  14.  
  15. System.out.printf("same = %d, different = %d\n", same.get(), diff.get());
  16. }
  17.  
  18. public static class Count extends RecursiveAction {
  19.  
  20. private static final long serialVersionUID = -6040618696103638659L;
  21.  
  22. protected final long max, min;
  23. protected final AtomicLong same, diff;
  24.  
  25. public Count(long min, long max, AtomicLong same, AtomicLong diff) {
  26. this.min = min;
  27. this.max = max;
  28. this.same = same;
  29. this.diff = diff;
  30. }
  31.  
  32. @Override
  33. protected void compute() {
  34. if (max - min <= (1 << 16)) {
  35. int same = 0;
  36. int diff = 0;
  37.  
  38. for (long i = this.min; i < this.max ; i++) {
  39. float f = Float.intBitsToFloat((int)i);
  40. if (f * 1.0f == f) {
  41. same++;
  42. } else {
  43. diff++;
  44. }
  45. }
  46.  
  47. this.diff.addAndGet(diff);
  48. this.same.addAndGet(same);
  49. } else {
  50. long mid = min + (max - min) / 2;
  51. invokeAll(new Count(min, mid, same, diff), new Count(mid, max, same, diff));
  52. }
  53. }
  54.  
  55. }
  56. }
  57.  
Time limit exceeded #stdin #stdout 5s 381696KB
stdin
Standard input is empty
stdout

Standard output is empty