poj3300

简单题

View Code
#include <iostream>
#include
<cstdio>
#include
<cstdlib>
#include
<cstring>
#include
<algorithm>
using namespace std;

#define maxn 50

struct D
{
int a, b;
} f[maxn
* maxn];

int n, m, tot;
int front[maxn], rear[maxn];

bool operator <(const D &a, const D &b)
{
return a.b * b.a < b.b * a.a;
}

void input()
{
tot
= 0;
scanf(
"%d", &m);
for (int i = 0; i < n; i++)
scanf(
"%d", &front[i]);
for (int i = 0; i < m; i++)
scanf(
"%d", &rear[i]);
}

void work()
{
for (int i = 0; i < n; i++)
for (int j = 0; j < m; j++)
{
f[tot].a
= front[i];
f[tot].b
= rear[j];
tot
++;
}
}

int main()
{
//freopen("t.txt", "r", stdin);
while (scanf("%d", &n), n)
{
input();
work();
sort(f, f
+ tot);
double ans = 0;
for (int i = 0; i < tot - 1; i++)
ans
= max(ans, f[i + 1].b * f[i].a * 1.0 / (f[i + 1].a * f[i].b));
printf(
"%.2f\n", ans);
}
return 0;
}
原文地址:https://www.cnblogs.com/rainydays/p/2129891.html