24h購物| | PChome| 登入
2013-07-07 21:25:27| 人氣603| 回應0 | 上一篇 | 下一篇

[UVA][模擬] 11242 - Tour de France

推薦 0 收藏 0 轉貼0 訂閱站台

Problem D: 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: 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 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.

Sample Input

2 4
40 50
12 14 16 19
0

Output for Sample Input

1.19

Ondrej Lhotak and Gordon V. Cormack

模擬處理即可。

#include <stdio.h>
#include <algorithm>
using namespace std;
int main() {
    int n, m, q;
    int i, j;
    double f[100], r[100], d[10000];
    while(scanf("%d %d", &n, &m) == 2) {
        q = 0;
        for(i = 0; i < n; i++)
            scanf("%lf", &f[i]);
        for(i = 0; i < m; i++)
            scanf("%lf", &r[i]);
        for(i = 0; i < n; i++)
            for(j = 0; j < m; j++)
                d[q++] = r[j]/f[i];
        sort(d, d+q);
        double mx = 0;
        for(i = 1; i < q; i++)
            mx = max(mx, d[i]/d[i-1]);
        printf("%.2lf\n", mx);
    }
    return 0;
}

台長: Morris
人氣(603) | 回應(0)| 推薦 (0)| 收藏 (0)| 轉寄
全站分類: 不分類 | 個人分類: UVA |
此分類下一篇:[UVA] 11203 - Can you decide it for ME
此分類上一篇:[UVA][dp] 10898 - Combo Deal

是 (若未登入"個人新聞台帳號"則看不到回覆唷!)
* 請輸入識別碼:
請輸入圖片中算式的結果(可能為0) 
(有*為必填)
TOP
詳全文