USACO Bronze 2019 December - Cow Gymnastics
Authors: Krish Thawani (Java), Hua Zhi Vee (C++)
Appears In
Java
// Created by Krish Thawaniimport java.io.*;import java.util.*;public class gymnastics {public static void main(String[] args) throws IOException {BufferedReader br = new BufferedReader(new FileReader("gymnastics.in"));PrintWriter pw = new PrintWriter(new FileWriter("gymnastics.out"));
C++
Alternate Solution
We generate the ranking as we read the data.
We create a 2D array of booleans which states if has a ranking higher than in any point of time. We read every ranking, then for all pairs we set .
Then we iterate though all pairs in time and check if they satisfy the condition. At least one of and must be true, and hence we only need to check if they are both true. If one of them is false, we increment our by 1.
Note that at least one of them must be true, since in every ranking either or .
Time Complexity:
#include<bits/stdc++.h>using namespace std;bool b[20][20]; // b[A-1][B-1] = 1 if A was better than B in any session.int main(){ifstream fin("gymnastics.in");ofstream fout("gymnastics.out");int k, n; fin >> k >> n;
Join the USACO Forum!
Stuck on a problem, or don't understand a module? Join the USACO Forum and get help from other competitive programmers!