### Re: 11001 - Necklace

Posted:

**Thu May 01, 2008 8:19 am**Anyone know why I'm getting WA?

Code: Select all

```
#include <stdio.h>
#include <math.h>
int v,v0;
double n,n0,n1,tmp1, tmp2;
int main(){
while (scanf("%d %d ",&v,&v0)!=EOF){
if (v0 == 0 && v == 0)
break;
if (v0>=v){
printf("0\n");
continue;
}
n = v;
n /= v0;
n /= 2.0;
n0 = floor(n);
n1 = ceil(n);
if (n0 == n1){
printf("%d\n",(int)n0);
continue;
}
tmp1 = v; tmp2 = v;
if (n0==0.0)
tmp1 = 0.0;
else
tmp1 = (tmp1/n0) - v0;
tmp2 = (tmp2/n1) - v0;
tmp1 = n0*sqrt(tmp1);
tmp2 = n1*sqrt(tmp2);
if (tmp1 == tmp2){
printf("0\n");
continue;
}
if (tmp1 < tmp2)
printf("%d\n",(int)n1);
else
printf("%d\n",(int)n0);
}
return 0;
}
```