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 1306. Sequence Median

I'm getting insane!!!now wa#2, althought I've tested it whit an AC program
Posted by Tusnad Nobrovirski 6 May 2007 15:03
here is my code. please help me :((

#include <stdio.h>
#define HMAX (1<<17)

int N;
unsigned int H[HMAX];

void sift(int x)
{
        int aux, up = x>>1;

        if (x < 1) return;

        if (H[x] > H[up])
        {
           aux = H[x]; H[x] = H[up]; H[up] = aux;
           sift(up);
        }
}

void perc(int x, int n)
{
        int l = x<<1, r = (x<<1)+1, max, aux;

        if (r > n) return;

        max = l;
        if (H[l] < H[r]) max = r;

        if (H[max] > H[x])
        {
           aux = H[max]; H[max] = H[x]; H[x] = aux;
           perc(max, 1+N/2);
        }
}

int main()
{
        int i, val;
        long double sol;
        unsigned int last, blast;

//        freopen("1306.in", "r", stdin);
        scanf("%d", &N);

        H[0] = 4294967295;

        for (i = 1; i <= 1+(N/2); i++)
                scanf("%lu", H+i);
        for (i = 1; i <= 1+(N/2); i++) sift(i);

        for (i = 2+(N/2); i <= N; i++)
        {
                scanf("%d", &val);
                if (val < H[1]) { H[1] = val; perc(1, 1+(N/2)); }
        }


        blast = H[1];
        H[1] = 0;
        perc(1, (N/2));
        last = H[1];

        sol = last*0.5;
        sol += blast*0.5;
        if ( (N&1) == 0 ) printf("%0.1llf\n", sol);
        else printf("%u\n", blast);

        return 0;

}
Re: I'm getting insane!!!now wa#2, althought I've tested it whit an AC program
Posted by Tusnad Nobrovirski 12 May 2007 01:56
please help me
Re: I'm getting insane!!!now wa#2, althought I've tested it whit an AC program
Posted by AlMag 12 May 2007 19:24
Try test with n=2.
FE
2
10
20
Re: I'm getting insane!!!now wa#2, althought I've tested it whit an AC program
Posted by FireHeart 2 Jun 2007 08:26
The result of my Program is 15.0
How about you ??
Re: I'm getting insane!!!now wa#2, althought I've tested it whit an AC program
Posted by Smilodon_am [Obninsk INPE] 12 Jan 2013 14:19
In my opinion, test #2 contain data like this:
1
5

Correct answer is:
5.0

I had a problem with output format. We should output the answer with one decimal digit after decimal point. My wrong program had written:
5
without fractional part.