Sunday, August 11, 2013

UVA 11242: Tour de France

straight iterative solution . If you have a difficulty in handling float arrays and comparing float numbers go for java. 

 

 

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.util.Arrays;
import java.util.Scanner;
import java.util.StringTokenizer;
public class Uva11242 {
/**
* @param args the command line arguments
*/
public static void main(String[] args) throws Exception {
BufferedReader br= new BufferedReader(new InputStreamReader(System.in));
Scanner sc= new Scanner(System.in);
String str;
while(true)
{
int f=sc.nextInt();
if(f==0)
break;
int r=sc.nextInt();
int[] front=new int[25],rear=new int[25];
for(int i=0;i<f;i++)
{
front[i]=sc.nextInt();
}
for(int i=0;i<r;i++)
{
rear[i]=sc.nextInt();
}
int n=f*r;
double[] arr= new double[r*f];
int t=0;
for(int i=0;i<f;i++)
{
for(int j=0;j<r;j++)
{
arr[t++]=rear[j]*1.00/front[i];
}
}
Arrays.sort(arr);
double max=0;
for(int i=1; i<arr.length ; i++)
{
max=Math.max(max, arr[i]/arr[i-1]);
}
System.out.printf("%.2f\n",max);
}
// TODO code application logic here
}
}
view raw UVA 11242 hosted with ❤ by GitHub

1 comment: