Online JudgeProblem SetAuthorsOnline ContestsUser
Web Board
Home Page
F.A.Qs
Statistical Charts
Problems
Submit Problem
Online Status
Prob.ID:
Register
Update your info
Authors ranklist
Current Contest
Past Contests
Scheduled Contests
Award Contest
User ID:
Password:
  Register

为什么WA?谁能帮我看看啊?

Posted by yeknight at 2010-04-16 12:49:49 on Problem 2379
#include <iostream>
#include <fstream>
using namespace std;

struct Team
{
    int number;
    int solve_num;
    int ttime;
};

struct Test
{
    int c;
    int p;
    int t;
    int r;
};

Test test[1001];
Team team[1001];

int cmp(const void *arg1,const void *arg2)
{
    Test *p1 = (Test*)arg1;
    Test *p2 = (Test*)arg2;

    if(p1->c != p2->c)
        return p1->c - p2->c;
    else
    {
        if(p1->p != p2->p)
            return p1->p - p2->p;
        else if(p1->r != p2->r)
            return p1->r - p2->r;
    }
    return 0;
}

int compare(const void *arg1,const void *arg2)
{
    Team *p1 = (Team*)arg1;
    Team *p2 = (Team*)arg2;

    if(p1->solve_num != p2->solve_num)
        return p2->solve_num - p1->solve_num;
    else if(p1->ttime != p2->ttime)
        return p1->ttime - p2->ttime;
    else
        return p1->number - p2->number;
    return 0;
}

int main()
{
    int m,n;
    fstream file;
    file.open("1.txt",ios::in | ios::out);
    file>>m>>n;
    int i;
    for(i = 1; i <= n; i++)
    {
        file>>test[i].c>>test[i].p>>test[i].t>>test[i].r;
    }

    qsort(test + 1,n,sizeof(Test),cmp);
    
    int time = 0;
    memset(team,0,sizeof(team));
    for(i = 1; i <= m; i++)
    {
        team[i].number = i;
    }
    for(i = 1; i <= n; i++)
    {
        if(test[i].r == 1)
        {
            if(test[i].c != test[i - 1].c || test[i].p != test[i - 1].p)
                time = 0;
            if(test[i].c == test[i - 1].c && test[i].p == test[i - 1].p && test[i - 1].r == 1)
                team[test[i].c].solve_num--;
            team[test[i].c].solve_num++;
            team[test[i].c].ttime += (time + test[i].t);
            team[test[i].c].number = test[i].c;
            time = 0;
        }
        else
        {
            if(test[i].c != test[i - 1].c || test[i].p != test[i - 1].p)
                time = 0;
            time += test[i].t;
        }
    }

    qsort(team + 1,m,sizeof(Team),compare);

    for(i = 1; i <= m; i++)
    {
        cout<<team[i].number<<" ";
    }
    cout<<endl;
    return 0;
}

Followed by:

Post your reply here:
User ID:
Password:
Title:

Content:

Home Page   Go Back  To top


All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator