poj3300

Tour de France

Time Limit: 1000MSMemory Limit: 65536K
Total Submissions: 3418Accepted: 1655

Description

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 : 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 d< d2 are adjacent if there is no other drive ratio d< d< d2. The spread between a pair of drive ratios d< d2 is their quotient: d2 ⁄ d1. You are to compute the maximum spread between two adjacent drive ratios achieved by a particular pair of front and rear clusters.

Input

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.

Output

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

Sample Input

2 4
40 50
12 14 16 19
0

Sample Output

1.19

Source


题目很难看懂,看了半天才发现是自行车变速器的问题。水过,补习英语去了。。。
#include <cstdio>
#include <algorithm>

using namespace std;

float ratio[100];
int f,r;
float front[10],rear[10];
float max_ratio;
int index;

int main()
{
    while(scanf("%d",&f)!=EOF && f)
    {
        scanf("%d",&r);
        for(int i=0; i<f; i++)
            scanf("%f",&front[i]);
        for(int i=0; i<r; i++)
            scanf("%f",&rear[i]);
        index=0;
        for(int i=0; i<r; i++)
        {
            for(int j=0; j<f; j++)
            {
                ratio[index++]=rear[i]/front[j];
            }
        }
        sort(ratio,ratio+index);
        for(int i=0; i<index-1; i++)
            ratio[i]=ratio[i+1]/ratio[i];
        max_ratio=0.0;
        for(int i=0; i<index-1; i++)
        {
            if(max_ratio<ratio[i])
                max_ratio=ratio[i];
        }
        printf("%.2f\n",max_ratio);

    }
    return 0;
}

转载于:https://www.cnblogs.com/eric-blog/archive/2011/06/01/2067441.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值