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 1066. Garland

Who can tell me why my programme is wrong? It seem to be so simple and I think is should be right.
Posted by Bolin, Ding 20 Oct 2002 18:36
#include<stdio.h>
//Who can tell me why my programme is wrong? It seem to be so
//simple and I think is should be right.
#define Max(a,b) (a>b?a:b)

typedef long double type;

double N;
type H1,H2;

int main()
{ float a;
  type i;
 scanf("%lf %f",&N,&a); H1=(type)a; H2=0;
 for (i=2; i<=N; i++) H2=Max(H2,(H1*(i-2)-(i-1)*(i-2))/(i-1));
 printf("%0.2lf\n",(double)Max(0,H2*(N-1)-H1*(N-2)+(N-1)*(N-2)));
 return 0;
}