Competitive/Collaborative Programming Class

ICPC Computer Programming Contest Prep

Problem Solving in Computer Science

Spring 2015 -- CSC 2700 Section 01

[Isaac's Home Page ]  [Mailing List ]  [Class Page ]  [Normal ]  

week08/b/Main.java

//Argus 1203

import java.util.*;

public class Main {

    Scanner cin=new Scanner(System.in);
    
    static int gcd(int a,int b){
        while(b!=0){
            int temp=a;
            a=b;
            b=a%b;
        }
        return a;
    }
    
    private class Event implements Comparable<Event>{
        int id;
        int interval;
        int next_event;
        
        @Override
        public int compareTo(Event other){
            if(this.next_event==other.next_event){
                return this.id-other.id;
            }
            return this.next_event-other.next_event;
        }
        
        public String toString(){
            return "("+id+","+interval+")";
        }
        
        Event(int i,int t){
            id=i;
            interval=t;
            next_event=t;
        }
    }
    
    public void doIt(){
        PriorityQueue<Event> evs=new PriorityQueue();
        String line=cin.nextLine();
        while(!line.contains("#")){
            String[] parts=line.split(" ");
            evs.add(new Event(Integer.parseInt(parts[1]),Integer.parseInt(parts[2])));
            line=cin.nextLine();
        }
        int num_events=cin.nextInt();
        while(num_events-- > 0){
            Event next=evs.remove();
            System.out.println(next.id);
            next.next_event+=next.interval;
            evs.add(next);
        }
    }
    
    public static void main(String[] args) {
        (new Main()).doIt();
    }
}

The statements and opinions included in these pages are those of only. Any statements and opinions included in these pages are not those of Louisiana State University or the LSU Board of Supervisors.
© 1999, 2000, 2001, 2002, 2003, 2004, 2005, 2006, 2007, 2008, 2009, 2010, 2011, 2012, 2013, 2014, 2015