ENG  RUSTimus Online Judge
Online Judge
Problems
Authors
Online contests
About Online Judge
Frequently asked questions
Site news
Webboard
Links
Problem set
Submit solution
Judge status
Guide
Register
Update your info
Authors ranklist
Current contest
Scheduled contests
Past contests
Rules
back to board

Discussion of Problem 1184. Cable Master

Who can tell me what's wrong with it?
Posted by Aleksei Zobnin 5 Apr 2002 00:13
#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?
Posted by sikee8 10 Apr 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?
Posted by sikee8 10 Apr 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?
Posted by Yitao 18 Sep 2007 21:08
But this is not a correct test...
"Cable lenth is at least 1 meter"...