Skip to content

Instantly share code, notes, and snippets.

Created October 28, 2009 15:56
Show Gist options
  • Save anonymous/220560 to your computer and use it in GitHub Desktop.
Save anonymous/220560 to your computer and use it in GitHub Desktop.
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
int main() {
int i,j,N,K,cas=1;
double ans,tmp;
// freopen("test.in", "r", stdin);
// freopen("test.out", "w", stdout);
while(scanf("%d%d", &N, &K) != EOF) {
if(N == 0 && K == 0)
break;
if(N == 1)
printf("Case %d: %.4f\n", cas++, 0.0);
else if(K * 2 + 1 >= N)
printf("Case %d: %.4f\n", cas++, (double)N);
else {
ans = 0.0;
for(i=N-1,j=N-(K*2+1),tmp=1.0; i>=N-K*2; i--,j--) {
tmp *= (double)j / i;
}
ans += (1.0 - tmp) * (N - K*2);
// printf("%f %f\n", tmp, ans);
for(i=N-K*2; i<=N-(K+1); i++) {
if(i - K*2 == 0) {
for(i=1,tmp=1.0; i<=K*2; i++) {
tmp *= (double)i / (N - K*2 + i - 1);
}
i--;
if(i >= N - K*2 && i <= N - (K + 1))
ans += (1.0 - tmp) * 2.0;
}
else {
tmp *= (double)i / (i - K*2);
ans += (1.0 - tmp) * 2.0;
}
// printf("%f %f\n", tmp, ans);
}
printf("Case %d: %.4f\n", cas++, ans);
}
}
return 0;
}
@evandrix
Copy link

Judge verdict: WA

@contnet
Copy link

contnet commented Jun 18, 2013

If you use the long double instead double, your code will get Accepted!!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment