Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package Problems;
- import java.util.*;
- public class acmtryouts1b {
- public static void main(String [] args) {
- Scanner stdin = new Scanner(System.in);
- ArrayList<ArrayList<Fox>> foxen = new ArrayList<ArrayList<Fox>>();
- int x = 0;
- int t;
- int n;
- int curTime = 0;
- String info;
- t = Integer.parseInt(stdin.nextLine().trim());
- for (int i = 0; i < t; i++) {
- n = Integer.parseInt(stdin.nextLine().trim());
- foxen.add(new ArrayList<Fox>());
- for (int j = 0; j < n; j++) {
- info = stdin.nextLine();
- String[] info2 = info.split(" ");
- int a = Integer.parseInt(info2[0]);
- int s = Integer.parseInt(info2[1]);
- int o = Integer.parseInt(info2[2]);
- foxen.get(i).add(new Fox(a, s, o, 0, false));
- }
- }
- for (int i = 0; i < t; i++) {
- while (x < foxen.get(i).size()) {
- x = 0;
- for (int j = 0; j < foxen.get(i).size(); j++) {
- Fox curFox = foxen.get(i).get(j);
- System.out.println(curFox.asleep);
- if (curFox.asleep) {
- x += 1;
- }
- else {
- x = 0;
- }
- curFox.runSleepCycle();
- }
- curTime += 1;
- if (curTime > 20000) {
- System.out.println("Foxen are too powerful");
- break;
- }
- }
- if (x == foxen.get(i).size()) {
- System.out.println(curTime-1);
- }
- }
- }
- }
- class Fox {
- public int a = 0;
- public int a2 = 0;
- public int s = 0;
- public int s2 = 0;
- public int o = 0;
- public boolean asleep = false;
- public Fox(int awake, int sleep, int time, int curTime, boolean asleep) {
- a = awake;
- s = sleep;
- o = time;
- if (this.a - this.o < 0) {
- this.asleep = true;
- this.s2 = this.o - this.a;
- }
- else if (this.a - this.o > 0) {
- this.asleep = false;
- this.a2 = this.a - this.o;
- }
- else {
- this.asleep = true;
- }
- }
- public void runSleepCycle() {
- if (this.asleep) {
- this.s2 += 1;
- if (this.s2 == this.s) {
- this.s2 = 0;
- this.asleep = false;
- }
- }
- else if (this.asleep == false) {
- this.a2 += 1;
- if (this.a2 == this.a) {
- this.a2 = 0;
- this.asleep = true;
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement