# USACO 2017 February Contest, Bronze Problem 1. Why Did the Cow Cross the Road

USACO2017-FEB-B1

import java.io.*;
import java.util.*;
public static void main(String[] args) throws IOException {
PrintWriter pw = new PrintWriter(new BufferedWriter(new FileWriter("crossroad.out")));

// read in the number of observations

// create an array to track the last known appearance of each cow
// lastSeen[cow] == 0 means we haven't seen the cow yet
// lastSeen[cow] == 1 means we have last seen the cow on the left side of the road
// lastSeen[cow] == 2 means we have last seen the cow on the right side of the road
int[] lastSeen = new int[11];

// track the number of crossings that are confirmed
int crossings = 0;
for(int i = 0; i < n; i++) {
// read in the data for one observation
int index = Integer.parseInt(st.nextToken());
int current = Integer.parseInt(st.nextToken())+1;

// if we have seen a cow already and the last side we saw it on is different
// from the current side, then it is a confirmed crossing
if(lastSeen[index] > 0 && lastSeen[index] != current) {
crossings++;
}

// update the last side we have seen the given cow on
lastSeen[index] = current;
}