首页 > 专题系列 > Java解POJ > POJ 3300 Tour de France [解题报告] Java
2013
11-12

POJ 3300 Tour de France [解题报告] Java

Tour de France

问题描述 :

A racing bicycle is driven by a chain connecting two sprockets. Sprockets are grouped into two clusters: the front cluster (typically consisting of 2 or 3 sprockets) and the rear cluster (typically consisting of between 5 and 10 sprockets). At any time the chain connects one of the front sprockets to one of the rear sprockets. The drive ratio — the ratio of the angular velocity of the pedals to that of the wheels — is n : m where n is the number of teeth on the rear sprocket and m is the number of teeth on the front sprocket. Two drive ratios d1 < d2 are adjacent if there is no other drive ratio d1 < d3 < d2. The spread between a pair of drive ratios d1 < d2 is their quotient: d2d1. You are to compute the maximum spread between two adjacent drive ratios achieved by a particular pair of front and rear clusters.

输入:

Input consists of several test cases, followed by a line containing 0. Each test case is specified by the following input:

  • f: the number of sprockets in the front cluster;
  • r: the number of sprockets in the rear cluster;
  • f integers, each giving the number of teeth on one of the gears in the front cluster;
  • r integers, each giving the number of teeth on one of the gears in the rear cluster.

You may assume that no cluster has more than 10 sprockets and that no gear has fewer than 10 or more than 100 teeth.

输出:

For each test case, output the maximum spread rounded to two decimal places.

样例输入:

2 4
40 50
12 14 16 19
0

样例输出:

1.19

解题代码:

//* @author: ccQ.SuperSupper
import java.io.*;
import java.util.*;

public class Main {
	static final int N = 20;
	static int n,m;
	static double front[] = new double[N],rear[] = new double[N],cnt[]=new double[N*N];
	
	static double Get_Num(StreamTokenizer cin)throws Exception{
		cin.nextToken();
		return cin.nval;
	}
	
public static void main(String[]args) throws Exception{
 int i;
 StreamTokenizer cin = new StreamTokenizer(new BufferedReader(new InputStreamReader(System.in)));
		
 while(true){
	n = (int) Get_Num(cin);
	if(n<=0) break;
	m = (int) Get_Num(cin);
	for(i=0;i< n;++i)
		front[i] = Get_Num(cin);
	for(i=0;i< m;++i)
		rear[i] = Get_Num(cin);
	System.out.printf("%.2f\n",solve());
  }
 }

static double solve(){
  double ans=0.0;
  int i,j,top=0;
  for(i=0;i< n;++i){
	for(j=0;j< m;++j){
		cnt[top++] = rear[j]/front[i];
	}
   }
  Arrays.sort(cnt,0,top);
  for(i=1;i< top;++i){
	ans = ans>(cnt[i]/cnt[i-1])?ans:(cnt[i]/cnt[i-1]);
  }
	return ans;
 }
}