fork download
  1. int goal;
  2. int[][] stateValue;
  3. boolean isOptimal(int money, int bet, int level) { // bet <= money
  4. return stateValue[level][money]
  5. == stateValue[level-1][min(goal, money+bet)]
  6. + stateValue[level-1][money-bet];
  7. }
  8. double[] pref;
  9. double upTo(int high) {
  10. if(high < pref.length) return pref[high];
  11. return pref[pref.length-1] + high - pref.length + 1;
  12. }
  13. double getInterval(int low, int high) {
  14. return upTo(high) - (low == 0 ? 0. : upTo(low - 1));
  15. }
  16. int divCeil(int a, int b) { return (a + b - 1) / b; }
  17. public double findProbability(int a, int tmp_b, int k) {
  18. goal = tmp_b;
  19. double[] ans = new double[goal];
  20. Arrays.fill(ans, 1.);
  21. stateValue = new int[k+1][goal+1];
  22. stateValue[0][goal] = 1;
  23. int[] spec = {0, goal};
  24. for(int level = 1; level <= k; ++level) {
  25. double[] old_ans = ans;
  26. pref = old_ans;
  27. for(int i = 1; i < pref.length; ++i)
  28. pref[i] += pref[i-1];
  29. ans = new double[goal+1];
  30. // compute spec[]
  31. int[] old_spec = spec;
  32. spec = new int[(1 << level) + 1];
  33. for (int i = 0; i <= (1 << level); ++i)
  34. spec[i] = divCeil(goal * i, 1 << level);
  35. // System.out.print("spec[] = "); write(spec);
  36. // compute stateValue[level][]
  37. for (int i = 0; i < (1 << level); ++i)
  38. for (int j = spec[i]; j < spec[i + 1]; ++j)
  39. stateValue[level][j] = i;
  40. stateValue[level][goal] = 1 << level;
  41. // main algorithm
  42. for (int start = 0; start < (1 << level); ++start) {
  43. double so_far = 0;
  44. int[] next = new int[(1 << (level - 1)) + 1];
  45. int[] begin = new int[(1 << (level - 1)) + 1];
  46. for (int i = 0; i <= 1 << (level - 1); ++i) {
  47. next[i] = old_spec[i];
  48. begin[i] = -1;
  49. }
  50. for(int from = spec[start]; from < spec[start+1]; ++from) {
  51. ans[from] = 0;
  52. for (int i = 0; i <= 1 << (level - 1); ++i) {
  53. if(begin[i] != -1) {
  54. begin[i] = max(from, begin[i]);
  55. if(begin[i] >= next[i]) begin[i] = -1;
  56. }
  57. while ((i == 1 << (level - 1) || next[i] < old_spec[i + 1])
  58. && next[i] <= 2 * from
  59. && (next[i] < from || isOptimal(from, next[i] - from, level))) {
  60. if(next[i] < from) {
  61. ++next[i];
  62. continue;
  63. }
  64. if(begin[i] == -1)
  65. begin[i] = next[i];
  66. ++next[i];
  67. }
  68.  
  69. if(begin[i] != -1) {
  70. ans[from] += getInterval(begin[i], next[i]-1);
  71. ans[from] += getInterval(2*from-(next[i]-1), 2 * from - begin[i]);
  72. }
  73. }
  74. ans[from] /= 2 * (from + 1);
  75. }
  76. }
  77. ans[goal] = 1;
  78. }
  79. return ans[a];
  80. }
Compilation error #stdin compilation error #stdout 0s 0KB
stdin
Standard input is empty
compilation info
Main.java:1: error: class, interface, or enum expected
	int goal;
	^
Main.java:2: error: class, interface, or enum expected
	int[][] stateValue;
	^
Main.java:3: error: class, interface, or enum expected
	boolean isOptimal(int money, int bet, int level) { // bet <= money
	^
Main.java:7: error: class, interface, or enum expected
	}
	^
Main.java:9: error: class, interface, or enum expected
	double upTo(int high) {
	^
Main.java:11: error: class, interface, or enum expected
		return pref[pref.length-1] + high - pref.length + 1;
		^
Main.java:12: error: class, interface, or enum expected
	}
	^
Main.java:15: error: class, interface, or enum expected
	}
	^
Main.java:16: error: class, interface, or enum expected
	int divCeil(int a, int b) { return (a + b - 1) / b; }
	                                                    ^
Main.java:17: error: class, interface, or enum expected
	public double findProbability(int a, int tmp_b, int k) {
	       ^
Main.java:19: error: class, interface, or enum expected
		double[] ans = new double[goal];
		^
Main.java:20: error: class, interface, or enum expected
		Arrays.fill(ans, 1.);
		^
Main.java:21: error: class, interface, or enum expected
		stateValue = new int[k+1][goal+1];
		^
Main.java:22: error: class, interface, or enum expected
		stateValue[0][goal] = 1;
		^
Main.java:23: error: class, interface, or enum expected
		int[] spec = {0, goal};
		^
Main.java:24: error: class, interface, or enum expected
		for(int level = 1; level <= k; ++level) {
		^
Main.java:24: error: class, interface, or enum expected
		for(int level = 1; level <= k; ++level) {
		                   ^
Main.java:24: error: class, interface, or enum expected
		for(int level = 1; level <= k; ++level) {
		                               ^
Main.java:26: error: class, interface, or enum expected
			pref = old_ans;
			^
Main.java:27: error: class, interface, or enum expected
			for(int i = 1; i < pref.length; ++i)
			^
Main.java:27: error: class, interface, or enum expected
			for(int i = 1; i < pref.length; ++i)
			               ^
Main.java:27: error: class, interface, or enum expected
			for(int i = 1; i < pref.length; ++i)
			                                ^
Main.java:29: error: class, interface, or enum expected
			ans = new double[goal+1];
			^
Main.java:31: error: class, interface, or enum expected
			int[] old_spec = spec;
			^
Main.java:32: error: class, interface, or enum expected
			spec = new int[(1 << level) + 1];
			^
Main.java:33: error: class, interface, or enum expected
			for (int i = 0; i <= (1 << level); ++i)
			^
Main.java:33: error: class, interface, or enum expected
			for (int i = 0; i <= (1 << level); ++i)
			                ^
Main.java:33: error: class, interface, or enum expected
			for (int i = 0; i <= (1 << level); ++i)
			                                   ^
Main.java:37: error: class, interface, or enum expected
			for (int i = 0; i < (1 << level); ++i)
			^
Main.java:37: error: class, interface, or enum expected
			for (int i = 0; i < (1 << level); ++i)
			                ^
Main.java:37: error: class, interface, or enum expected
			for (int i = 0; i < (1 << level); ++i)
			                                  ^
Main.java:38: error: class, interface, or enum expected
				for (int j = spec[i]; j < spec[i + 1]; ++j)
				                      ^
Main.java:38: error: class, interface, or enum expected
				for (int j = spec[i]; j < spec[i + 1]; ++j)
				                                       ^
Main.java:40: error: class, interface, or enum expected
			stateValue[level][goal] = 1 << level;
			^
Main.java:42: error: class, interface, or enum expected
			for (int start = 0; start < (1 << level); ++start) {
			^
Main.java:42: error: class, interface, or enum expected
			for (int start = 0; start < (1 << level); ++start) {
			                    ^
Main.java:42: error: class, interface, or enum expected
			for (int start = 0; start < (1 << level); ++start) {
			                                          ^
Main.java:44: error: class, interface, or enum expected
				int[] next = new int[(1 << (level - 1)) + 1];
				^
Main.java:45: error: class, interface, or enum expected
				int[] begin = new int[(1 << (level - 1)) + 1];
				^
Main.java:46: error: class, interface, or enum expected
				for (int i = 0; i <= 1 << (level - 1); ++i) {
				^
Main.java:46: error: class, interface, or enum expected
				for (int i = 0; i <= 1 << (level - 1); ++i) {
				                ^
Main.java:46: error: class, interface, or enum expected
				for (int i = 0; i <= 1 << (level - 1); ++i) {
				                                       ^
Main.java:48: error: class, interface, or enum expected
					begin[i] = -1;
					^
Main.java:49: error: class, interface, or enum expected
				}
				^
Main.java:50: error: class, interface, or enum expected
				for(int from = spec[start]; from < spec[start+1]; ++from) {
				                            ^
Main.java:50: error: class, interface, or enum expected
				for(int from = spec[start]; from < spec[start+1]; ++from) {
				                                                  ^
Main.java:52: error: class, interface, or enum expected
					for (int i = 0; i <= 1 << (level - 1); ++i) {
					^
Main.java:52: error: class, interface, or enum expected
					for (int i = 0; i <= 1 << (level - 1); ++i) {
					                ^
Main.java:52: error: class, interface, or enum expected
					for (int i = 0; i <= 1 << (level - 1); ++i) {
					                                       ^
Main.java:55: error: class, interface, or enum expected
							if(begin[i] >= next[i]) begin[i] = -1;
							^
Main.java:56: error: class, interface, or enum expected
						}
						^
Main.java:62: error: class, interface, or enum expected
								continue;
								^
Main.java:63: error: class, interface, or enum expected
							}
							^
Main.java:66: error: class, interface, or enum expected
							++next[i];
							^
Main.java:67: error: class, interface, or enum expected
						}
						^
Main.java:71: error: class, interface, or enum expected
							ans[from] += getInterval(2*from-(next[i]-1), 2 * from - begin[i]);
							^
Main.java:72: error: class, interface, or enum expected
						}
						^
Main.java:75: error: class, interface, or enum expected
				}
				^
Main.java:78: error: class, interface, or enum expected
		}
		^
Main.java:80: error: class, interface, or enum expected
	}
	^
60 errors
stdout
Standard output is empty