Explanation for USACO 2014 Silver Contest Marathon

Problem Statement: USA Computing Olympiad

Problem Solution: Contest Results

Problem Summary: Essentially the problem describes Bessie the cow traveling through a course consisting of N checkpoints visited in sequence. However, being lazy, Bessie decides to skip K checkpoints where K < N (She cannot skip the first and last checkpoints as well). We must find the minimum distance Bessie is required to run by skipping K checkpoints. In this case, the distances are computed as Manhattan distances where the distance from x to y would be represented as: |x1-x2| + |y1-y2|.

Question: The issue is I am having trouble wrapping my head around the dynamic programming solution (linked above). Could someone provide a through explanation of the steps in discovering such a dynamic programming solution as well? Thanks for the support!

How to open Android Clock Application?

How I can open Android Clock Application in my android application? I read a lot of posts from stackoverflow how to do it, but everywhere is described how to open AlarmClock. But in my situation I want to show to user only clock application. How I can implement it?

Spring-Maven Project: Unsupported major.minor version 52.0 stubborn error

I am downgrading a small application from Tomcat 8/JRE 1.8 to Tomcat 7/JRE 1.7 for infrastructure reasons. Nevertheless, when I set up JRE to 1.7 and compiler compliance level to 1.7, I got this error in Tomcat 7 start-up. I’ve tried everything in this question, without success.

  • Compiler compliance level: 1.7
  • Targeted runtimes: Apache Tomcat v7.0
  • JRE System Library: jdk1.7.0_80

Maven POM snippet:


Any help would be worthy. Thanks.

java.util.concurrent.ExecutionException: org.apache.catalina.LifecycleException: Failed to start component [StandardEngine[Catalina].StandardHost[localhost].StandardContext[/compoT7]]
    at java.util.concurrent.FutureTask.report(FutureTask.java:122)
    at java.util.concurrent.FutureTask.get(FutureTask.java:188)
    at org.apache.catalina.core.ContainerBase.startInternal(ContainerBase.java:1119)
    at org.apache.catalina.core.StandardHost.startInternal(StandardHost.java:819)
    at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:145)
    at org.apache.catalina.core.ContainerBase$StartChild.call(ContainerBase.java:1571)
    at org.apache.catalina.core.ContainerBase$StartChild.call(ContainerBase.java:1561)
    at java.util.concurrent.FutureTask.run(FutureTask.java:262)
    at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1145)
    at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:615)
    at java.lang.Thread.run(Thread.java:745)
Caused by: org.apache.catalina.LifecycleException: Failed to start component [StandardEngine[Catalina].StandardHost[localhost].StandardContext[/compoT7]]
    at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:162)
    ... 6 more
Caused by: java.lang.UnsupportedClassVersionError: org/springframework/web/SpringServletContainerInitializer : Unsupported major.minor version 52.0 (unable to load class org.springframework.web.SpringServletContainerInitializer)
    at org.apache.catalina.loader.WebappClassLoaderBase.findClassInternal(WebappClassLoaderBase.java:3209)
    at org.apache.catalina.loader.WebappClassLoaderBase.findClass(WebappClassLoaderBase.java:1373)
    at org.apache.catalina.loader.WebappClassLoaderBase.loadClass(WebappClassLoaderBase.java:1861)
    at org.apache.catalina.loader.WebappClassLoaderBase.loadClass(WebappClassLoaderBase.java:1735)
    at java.lang.Class.forName0(Native Method)
    at java.lang.Class.forName(Class.java:278)
    at org.apache.catalina.startup.WebappServiceLoader.loadServices(WebappServiceLoader.java:197)
    at org.apache.catalina.startup.WebappServiceLoader.load(WebappServiceLoader.java:158)
    at org.apache.catalina.startup.ContextConfig.processServletContainerInitializers(ContextConfig.java:1579)
    at org.apache.catalina.startup.ContextConfig.webConfig(ContextConfig.java:1280)
    at org.apache.catalina.startup.ContextConfig.configureStart(ContextConfig.java:888)
    at org.apache.catalina.startup.ContextConfig.lifecycleEvent(ContextConfig.java:388)
    at org.apache.catalina.util.LifecycleSupport.fireLifecycleEvent(LifecycleSupport.java:117)
    at org.apache.catalina.util.LifecycleBase.fireLifecycleEvent(LifecycleBase.java:90)
    at org.apache.catalina.core.StandardContext.startInternal(StandardContext.java:5522)
    at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:145)
    ... 6 more

hibernate unable to load extended class entity column names if parent class uses lombok annotation

Hi I’m using lombok api with entity class having @Data annotation which extends audit class (common columns) which is simple abstract class with @MappedSuperclass and @Data annotation. But when hibernate-jpa loads it is not picking up the column names but instead its picking up actual member variable names.

@Table(name = "TEST_TYPES", schema = "TESTER")
@EqualsAndHashCode(callSuper = false, of = {"id"})
public class TestEntity extends AuditEntity {
    @Column(name = "TYPE_ID")
    private Short id;

    @Column(name = "NAME")
    private String name;    

public abstract class AuditEntity implements Serializable {
    private static final long serialVersionUID = 3487394229267512541L;

    @Column(name = "CREATED_BY", length = 40)
    private String createdBy;

    @Column(name = "CREATED_DATE", length = 7)
    private Date createdDate;    

Hibernate throwing this error..
Caused by: java.sql.SQLSyntaxErrorException: ORA-00904: “TESTPROJJU0_”.”CREATEDBY”: invalid identifier

hibernate should pick the column name ie “CREATED_BY” but it is picking up “createdby”

I appreciate any suggestion/help.

Get the values which are unique in a given list [duplicate]

This question already has an answer here:

Is there a simple way to get a list of the unique values of a given list in java?

For example :

List<Integer> a = new ArrayList(Arrays.asList(1,2,2,2,3,3,4,5));
List<Integer> b = getUniqueValues(a);

Give the output :


I would like to know if its exists a simple way to have this getUniqueValues() function in java.

All that I find on internet are ways to return the list of distinct elements (in my example, the ouput would be [1,2,3,4,5]) : that is not what I want.

Java validating user integer input

I have written code which

1) Continously asking user to select number and check if input is integer

private static int readInputInt(String error) {
    Scanner s = new Scanner(System.in);
    while (!s.hasNextInt()) {
    int result = s.nextInt();
    return result;

2) Continously asking user to select number within range and showing only errors, program do not show message to ask user to provide input once again.

private static int readInputInt(String error, int max) {
    Scanner s = new Scanner(System.in);
    int result;
    do {
        while(!s.hasNextInt()) {
            //show error if it is not integer and get input once again
        result = s.nextInt();
        // if result is integer check if it is bigger than max
        if(result > max) {

    }while(result > max);

and I was wondering if there is any simpler way to do this because I spent too much time for this and I think it is rubbish way of coding.

Firsly I tought that below code will work:

private static int readInputInt(String error, int max) {
    Scanner s = new Scanner(System.in);
    while (!s.hasNextInt() && (s.nextInt < max)) {
    int result = s.nextInt();
    return result;

but it don’t work. For any help thank you!

AMQ Consumers choose which queue to process

Given the following scenario:

I have a system that creates, updates and deletes records. For each of these actions I need to do something (lets say write the events to a log as a silly example) however I need to process these events for each record in order – Meaning I can’t log the delete before I have done the create, or any of the previous updates. I also can’t log the update before I have logged the create.

I am investigating Queues in order to preserve sequence. However I don’t really want RecordID_2 to be held up behind RecordID_14 The records do not need to be processed in sequence as much as the actions on each record have to. Hence I don’t think I can/should use one queue.

As I don’t have hundreds of RecordID_XX active at the same time, I was thinking of having a queue for each RecordID_XX so if several updates can in for that one RecordID each event for that record would be added to that same queue and be processed in order (I.e. Create first, Update_1 after Create is complete, Update_2 is processed after Update_1 is complete etc), however if additional events for a different record came in they would be added to their own queue. If the queue is empty for a period of time it simply gets deleted. I realize that this may result in a queue getting one message and then being deleted as there were no updates before the idle timeout expired. (This does not seem at all efficient)

Based on Andres T Finnell’s excellent answer to this question.

I was thinking of doing the following

Producer (Web Service) -> Queue_Original <- Dispatcher  -> RecordID_14 
                                                        -> RecordID_2 
                                                        -> RecordID_8
                                                        -> RecordID_15

Some of the “logging” may take long. So I want to be able to have a few consumers listening for these queues.

Lets say I have Consumer_1 and Consumer_2 (I may want to add Consumer_3 later to assist with growing load)

What I would like is Consumer_1 to do a getDistinations()
where the broker will return [RecordID_14, RecordID_2, RecordID_8, RecordID_15]

Is it possible for Consumer_1 to iterate through the list of queues returned from the broker looking for the first available queue that does not have a Consumer_X connected to it and begin processing the 1st message on this queue? And then each subsequent Consumer to do the same until it finds the next queue without a Consumer connected to it?

Am I going down the wrong path completely? Is there a better approach to handling this scenario?