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 1821. Biathlon

WA #2 ?
Posted by Uzbek boy 11 Oct 2011 03:25
please, give me any test for WA #2
WA#2
Posted by Siroj Matchanov [TUIT] 26 Oct 2011 01:48
I'm sick of it. Please explain it to me. I'm getting WA2.

What am I doing wrong?

This is my code:
#include "stdio.h"
#include "algorithm"
#include "string.h"

struct time
{
    double s, os; //os - original time
    // s - finish time (+id*30)
    char name[21];
    int I;
    time(const double S = 0, const int id = 0)
        :s(S), I(id) {}
    void inc(const int id)
    {
        os = s;
        s += 30*id;
    }
};

int cmp(const void* a, const void* b)
{
    return ( ((time*)a)->s > ((time*)b)->s );
}

int cmp2(const void* a, const void* b)
{
    return strcmp(((time*)a)->name, ((time*)b)->name);
}

int cmp3(const void* a, const void* b)
{
    return ( ((time*)a)->os < ((time*)b)->os );
}

int main()
{
    int n;
    scanf("%d\n", &n);

    time* ts = new time[n+1];
    time* ans = new time[n+1];
    int m;
    float t;
    for(int i=0; i<n; i++)
    {
        scanf("%s %d:%f\n", ts[i].name, &m, &t );
        ts[i].s = t + m * 60;
        ts[i].inc(i);
    }

    std::qsort(&ts[1], n-1, sizeof(time), cmp);
    int j=0;
    ans[j++] = ts[0];
    for(int i=1; i<n; i++)
    {
        if( cmp3( &ts[i], &ans[j-1])  ) ans[j++] = ts[i];
    }
    std::qsort(ans,j,sizeof(time),cmp2);
    printf("%d\n",j);
    for(int i=0;i<j;i++) printf("%s\n", ans[i].name);

    delete[] ans;
    delete[] ts;
    return 0;
}

Edited by author 26.10.2011 01:51