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

为什么会Runtime error? 实在查不出来,拜托帮忙检查检查!(附程序)

Posted by vigour at 2007-05-02 01:16:58 on Problem 1456
#include<iostream.h>
using namespace std;
#define MAX 10001

struct node
{
       int a,b;
}product[MAX];

int compare(const void *p,const void *q)
{
    return (*(node*)p).a>(*(node*)q).a?1:-1;  
}

int main()
{
    int n,i,j,deadline,maxValue,maxone,total;
    bool s[MAX];
    
    while(scanf("%d",&n)!=EOF)
    {
        deadline=0;
        for(i=0;i<n;i++)
        { scanf("%d%d",&product[i].b,&product[i].a); 
          if(deadline<product[i].a) deadline=product[i].a; 
          s[i]=false;
        }
        // b[i]表示价值,a[i]表示期限
        qsort(product,n,sizeof(node),compare);
        total=0;
        for(i=deadline;i>=1;i--)
        {
            maxValue=0; maxone=-1;
            j=n-1;
            while(product[j].a >=i && j>=0)
            {
                if(s[j]!=true && product[j].b>maxValue) {maxValue=product[j].b; maxone=j;}
                j--;       
            }
            if(maxone!=-1) 
                total+=product[maxone].b;
            s[maxone]=true;
        }
        printf("%d\n",total);
    }
}

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