Advertisement
Guest User

Untitled

a guest
Sep 19th, 2014
226
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.12 KB | None | 0 0
  1. package Problems;
  2.  
  3. import java.util.*;
  4.  
  5. public class acmtryouts1b {
  6. public static void main(String [] args) {
  7. Scanner stdin = new Scanner(System.in);
  8.  
  9. ArrayList<ArrayList<Fox>> foxen = new ArrayList<ArrayList<Fox>>();
  10.  
  11. int x = 0;
  12. int t;
  13. int n;
  14. int curTime = 0;
  15. String info;
  16.  
  17. t = Integer.parseInt(stdin.nextLine().trim());
  18.  
  19. for (int i = 0; i < t; i++) {
  20. n = Integer.parseInt(stdin.nextLine().trim());
  21. foxen.add(new ArrayList<Fox>());
  22. for (int j = 0; j < n; j++) {
  23. info = stdin.nextLine();
  24. String[] info2 = info.split(" ");
  25. int a = Integer.parseInt(info2[0]);
  26. int s = Integer.parseInt(info2[1]);
  27. int o = Integer.parseInt(info2[2]);
  28. foxen.get(i).add(new Fox(a, s, o, 0, false));
  29. }
  30. }
  31.  
  32. for (int i = 0; i < t; i++) {
  33. while (x < foxen.get(i).size()) {
  34. x = 0;
  35. for (int j = 0; j < foxen.get(i).size(); j++) {
  36. Fox curFox = foxen.get(i).get(j);
  37. System.out.println(curFox.asleep);
  38. if (curFox.asleep) {
  39. x += 1;
  40. }
  41. else {
  42. x = 0;
  43. }
  44. curFox.runSleepCycle();
  45. }
  46. curTime += 1;
  47. if (curTime > 20000) {
  48. System.out.println("Foxen are too powerful");
  49. break;
  50. }
  51. }
  52. if (x == foxen.get(i).size()) {
  53. System.out.println(curTime-1);
  54. }
  55. }
  56.  
  57. }
  58. }
  59.  
  60. class Fox {
  61. public int a = 0;
  62. public int a2 = 0;
  63. public int s = 0;
  64. public int s2 = 0;
  65. public int o = 0;
  66. public boolean asleep = false;
  67.  
  68. public Fox(int awake, int sleep, int time, int curTime, boolean asleep) {
  69. a = awake;
  70. s = sleep;
  71. o = time;
  72.  
  73. if (this.a - this.o < 0) {
  74. this.asleep = true;
  75. this.s2 = this.o - this.a;
  76. }
  77. else if (this.a - this.o > 0) {
  78. this.asleep = false;
  79. this.a2 = this.a - this.o;
  80. }
  81. else {
  82. this.asleep = true;
  83. }
  84.  
  85. }
  86.  
  87. public void runSleepCycle() {
  88. if (this.asleep) {
  89. this.s2 += 1;
  90. if (this.s2 == this.s) {
  91. this.s2 = 0;
  92. this.asleep = false;
  93. }
  94. }
  95. else if (this.asleep == false) {
  96. this.a2 += 1;
  97. if (this.a2 == this.a) {
  98. this.a2 = 0;
  99. this.asleep = true;
  100. }
  101. }
  102. }
  103.  
  104.  
  105. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement