|
|
вернуться в форумWho can tell me what's wrong with it? #include <stdio.h> #include <math.h> int n, k; double * data; int ok (double z) { long s = 0; for (int i = 0; i < n; i++) s += floor (data[i] / z); return s >= k; } int main () { scanf ("%d%d", &n, &k); data = new double [n]; double l; for (int i = 0; i < n; i++) { scanf ("%lf", &l); data[i] = l; } if (!ok(0.01)) { printf ("0.00\n"); return 0; } double x = 0.01, y = 1e5, z; while (y - x >= 0.0001) { z = (x + y) / 2; if (ok(z)) x = z; else y = z; } printf ("%.2lf\n", z); return 0; } Re: Who can tell me what's wrong with it? Послано sikee8 10 апр 2002 22:07 Wrong Answer. simple test: 5 10 3.34 2.34 7.54 1.87 0.03 your answer: 1.26 but 7.54/1.25 = 5 (1.26*6 = 7.56) and you have only 9 cables with length 1.26: 2 + 1 + 5 + 1 + 0 = 9 3.34 2.34 7.54 1.87 0.03 a have this mistake too :)) Re: Who can tell me what's wrong with it? Послано sikee8 10 апр 2002 22:07 Wrong Answer. simple test: 5 10 3.34 2.34 7.54 1.87 0.03 your answer: 1.26 but 7.54/1.26 = 5 (1.26*6 = 7.56) and you have only 9 cables with length 1.26: 2 + 1 + 5 + 1 + 0 = 9 3.34 2.34 7.54 1.87 0.03 a have this mistake too :)) Re: Who can tell me what's wrong with it? Послано Yitao 18 сен 2007 21:08 But this is not a correct test... "Cable lenth is at least 1 meter"... |
|
|