Advertisement
Guest User

Untitled

a guest
Oct 6th, 2015
96
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.09 KB | None | 0 0
  1. public static boolean train() {
  2. int max_passengers = 1;
  3.  
  4. int[][] rides = {{0,1,1}, {1,0,0}};
  5. // int[][] rides = {{1,0,0}, {0,1,0}};
  6. // int[][] rides = {{0,1,0}, {1,0,1}};
  7. // int[][] rides = {{0,1,1}, {0,0,0}};
  8.  
  9. int passengers = 0;
  10. for(int i = 0; i < rides.length; i++) {
  11. // passengers leave
  12. passengers -= rides[i][0];
  13. if(passengers < 0) return false;
  14.  
  15. // passengers enter
  16. passengers += rides[i][1];
  17. if(passengers > max_passengers) return false;
  18.  
  19. // if train is not filled and ppl are waiting
  20. if(passengers < max_passengers && rides[i][2] > 0) return false;
  21. }
  22.  
  23. // all passengers should have left the train
  24. return passengers == 0;
  25. }
  26.  
  27. public static boolean clock() {
  28. int[] a = {1,2,4,5,6,13};
  29. int[] b = new int[a.length];
  30. for(int i = 0; i < b.length; i++)
  31. b[i] = (a[i] + 1) % 360;
  32.  
  33. Arrays.sort(a);
  34. Arrays.sort(b);
  35.  
  36. System.out.println(Arrays.toString(a));
  37. System.out.println(Arrays.toString(b));
  38. System.out.println("");
  39.  
  40. int[] dist_a = new int[a.length];
  41. int[] dist_b = new int[b.length];
  42. for(int i = 0; i < a.length; i++) {
  43. dist_a[i] = a[(i+1)%a.length] - a[i];
  44. while(dist_a[i] < 0) dist_a[i] += 360;
  45.  
  46. dist_b[i] = b[(i+1)%b.length] - b[i];
  47. while(dist_b[i] < 0) dist_b[i] += 360;
  48. }
  49.  
  50. for(int off = 0; off < a.length; off++) {
  51. boolean same = true;
  52. for(int i = 0; i < a.length; i++) {
  53. if(dist_a[i] != dist_b[(i+off)%dist_b.length]) {
  54. same = false;
  55. break;
  56. }
  57. }
  58.  
  59. if(same) return same;
  60. }
  61.  
  62. //System.out.println(Arrays.toString(dist_a));
  63. //System.out.println(Arrays.toString(dist_b));
  64.  
  65. return false;
  66. }
  67.  
  68. public static void explosions() {
  69. int[] heights = {2,1,4,1,3,4,8,1,1,10};
  70. Arrays.sort(heights);
  71. int num = heights.length;
  72. System.out.println(num + " : "+Arrays.toString(heights));
  73.  
  74. int last = 0;
  75. int max = 0;
  76. for(int i = 0; i < num; i++) {
  77. if(heights[i] < i) {
  78. last = i;
  79. if(heights[i] > max)
  80. max = heights[i];
  81. }
  82. }
  83.  
  84. System.out.println("explosions: " + (max + (num - last - 1)));
  85. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement