Which god did
B may not be selected device bandwidth values ??do?
I mean, B and P, three prices are not a device? Namely: B / P in P B may not correspond to the bandwidth of the three devices do? Or B may be any of all the data with a bandwidth?
seeking answers
------ Solution ---------------------------------- ----------
and that the optimal solution must be qualified.
------ For reference only -------------------------------------- -
Each device can choose from several manufacturer.
After selecting, B is a device where you choose the smallest B, P is the device you choose where P combined. To maximize the B / P.
------ For reference only -------------------------------------- -
# include
# include
int main ()
{
int i, j, k, m, min, max, high, low, t, sum;
int b [101] [101], p [101] [101], num [101], flag [32767];
double b_p, mmax;
scanf ("% d", & t);
while (t -)
{
memset (flag, 0, sizeof (flag));
high = 32767;
low = 32767;
scanf ("% d", & m);
for (i = 0; i
min = 32767;
max = 0;
scanf ("% d", & num [i]);
for (j = 0; j
scanf ("% d", & b [i] [j]);
scanf ("% d", & p [i] [j]);
flag [b [i] [j]] = 1;
if (max max = b [i] [j];
if (min> b [i] [j])
min = b [i] [j];
}
if (low> min)
low = min;
if (high> max)
high = max;
}
mmax = 0;
for (i = low; i <= high; i + +)
{
if (flag [i])
{
sum = 0;
for (j = 0; j
min = 32767;
for (k = 0; k
if (b [j] [k]> = i)
{
if (min> = p [j] [k])
min = p [j] [k];
}
}
sum + = min;
}
b_p = (double) i / (double) sum;
if (mmax
}
}
printf ("% .3 lf \ n", mmax);
}
return 0;
}
But this algorithm does not consider the loop B, B and P in a price is a manufacturer's
For example, enter:
1 3
3 100 25 150 15 80 25
2 120 80 155 40
2 100 100 120 110
When the loop B = 80, P-selectin in the first row with 15 instead of 25, but 25 and 80 is not a manufacturer's bandwidth and price?
However, this algorithm AC up. . . .
------ For reference only -------------------------------------- -
That is because when this happens is not necessarily optimal. Although it will cycle to the cycle but there will certainly be a more optimal solution overwrite it.
------ For reference only -------------------------------------- -
Thank you very much! Hey, infrastructure is poor. . .
没有评论:
发表评论