Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public static boolean train() {
- int max_passengers = 1;
- int[][] rides = {{0,1,1}, {1,0,0}};
- // int[][] rides = {{1,0,0}, {0,1,0}};
- // int[][] rides = {{0,1,0}, {1,0,1}};
- // int[][] rides = {{0,1,1}, {0,0,0}};
- int passengers = 0;
- for(int i = 0; i < rides.length; i++) {
- // passengers leave
- passengers -= rides[i][0];
- if(passengers < 0) return false;
- // passengers enter
- passengers += rides[i][1];
- if(passengers > max_passengers) return false;
- // if train is not filled and ppl are waiting
- if(passengers < max_passengers && rides[i][2] > 0) return false;
- }
- // all passengers should have left the train
- return passengers == 0;
- }
- public static boolean clock() {
- int[] a = {1,2,4,5,6,13};
- int[] b = new int[a.length];
- for(int i = 0; i < b.length; i++)
- b[i] = (a[i] + 1) % 360;
- Arrays.sort(a);
- Arrays.sort(b);
- System.out.println(Arrays.toString(a));
- System.out.println(Arrays.toString(b));
- System.out.println("");
- int[] dist_a = new int[a.length];
- int[] dist_b = new int[b.length];
- for(int i = 0; i < a.length; i++) {
- dist_a[i] = a[(i+1)%a.length] - a[i];
- while(dist_a[i] < 0) dist_a[i] += 360;
- dist_b[i] = b[(i+1)%b.length] - b[i];
- while(dist_b[i] < 0) dist_b[i] += 360;
- }
- for(int off = 0; off < a.length; off++) {
- boolean same = true;
- for(int i = 0; i < a.length; i++) {
- if(dist_a[i] != dist_b[(i+off)%dist_b.length]) {
- same = false;
- break;
- }
- }
- if(same) return same;
- }
- //System.out.println(Arrays.toString(dist_a));
- //System.out.println(Arrays.toString(dist_b));
- return false;
- }
- public static void explosions() {
- int[] heights = {2,1,4,1,3,4,8,1,1,10};
- Arrays.sort(heights);
- int num = heights.length;
- System.out.println(num + " : "+Arrays.toString(heights));
- int last = 0;
- int max = 0;
- for(int i = 0; i < num; i++) {
- if(heights[i] < i) {
- last = i;
- if(heights[i] > max)
- max = heights[i];
- }
- }
- System.out.println("explosions: " + (max + (num - last - 1)));
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement