import java.io.PrintStream; import java.util.ArrayList; import java.util.Arrays; import java.util.Collections; import java.util.Scanner; /** * Solution to Gears * * @author vanb */ public class gears_vanb { /** Input. */ private static Scanner sc; /** Output. */ private static PrintStream ps; /** * Do it! */ private void doit() { ArrayList gears[] = new ArrayList[100000]; Arrays.fill( gears, null ); // Capture all of the gears that have the same tooth size. int n = sc.nextInt(); while( n-->0 ) { int s = sc.nextInt()-1; int c = sc.nextInt(); if( gears[s]==null ) gears[s] = new ArrayList(); // The log will be more useful gears[s].add( Math.log( c ) ); } // We can only match gears within the same tooth size list. // So sort them and match biggest with smallest, nest biggest with next smallest and so on. // The angular velocity will be the product of the big ones divided by the product of the small ones. // Since we're dealing with logs, that's adding and subtracting instead of multiplying and dividing. double angular = 0.0; for(ArrayList gear : gears ) if( gear!=null ) { n = gear.size(); Collections.sort( gear ); // Go halfway, match a big one (at the end) with a small one (at the front) for( int i=0; i