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 1572. Yekaterinozavodsk Great Well

rohit WA3 [2] // Problem 1572. Yekaterinozavodsk Great Well 16 May 2008 02:31
This is my code.
#include<stdio.h>
#include<math.h>
double min(int t,int s)
{
    switch (t)
    {
        case 1:
            return 2*s;
        case 2:
            return (double)s;
        default:
            return ((s/2)*sqrt(3.0));
    }
}
double max(int t,int s)
{
    switch (t)
    {
        case 1:
            return 2*s;
        case 2:
            return (s*sqrt(2.0));
        default:
            return (double)s;
    }
}
void main()
{
    int htype,hsize;
    int type,size;
    double max_len,min_len;
    int n,c=0;
    int i;
    scanf("%d %d",&htype,&hsize);
    max_len=max(htype,hsize);
    scanf("%d",&n);
    for (i=0;i<n;i++)
    {
        scanf("%d %d",&type,&size);
        min_len=min(type,size);
        if (min_len<=max_len)
            c++;
    }
    printf("%d",c);
}

Please tell me whats wrong..
Smilodon_am [Obninsk INPE] Re: WA3 [1] // Problem 1572. Yekaterinozavodsk Great Well 22 Oct 2009 13:50
Perhaps, the error is in the function "min".
In case of triangle you

return ((s/2)*sqrt(3.0));

But in C++ when "s" is "int" and "2" is "int", you will get not float division but only integer division. So when s==3, for example,

((s/2)*sqrt(3.0))==1*sqrt(3.0)

You may write "s/2.0".
rohit Re: WA3 // Problem 1572. Yekaterinozavodsk Great Well 27 Jul 2010 23:02
Thanks..AC now. Such a silly mistake.